Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
Konva Fail Cannot read properties of undefined (reading 'newLine') from Array

I have a Problem on Konva, this script draw some point and lines between the point and dragable i want to select the lines oder points and when i hover or click on the created line/point i have an error eg: Uncaught TypeError: Cannot read properties of undefined (reading 'newLine')

function updateObjects() {      
var shapes = stage.find('.line');

shapes.forEach((shape) => {
    shape.destroy();
})

targets.forEach((target) => {
    (function () {
        if (targets.length > 1) {
            if (target.id != targets.length - 1) {
                const targid = '#targets' + target.id;
                const targid2 = '#targets' + (target.id + 1);
                var ctarg = stage.find(targid)[0];
                var entarg = stage.find(targid2)[0];

                if (ctarg != null && entarg != null) {
                    var newLine = new Konva.Line({
                        points: [ctarg.x(), ctarg.y(), entarg.x(), entarg.y()],
                        stroke: 'black',
                        strokeWidth: 5,
                        lineCap: 'round',
                        lineJoin: 'round',
                        id: 'lineId=' + idCounter,
                        name: 'line',
                    });

                    idCounter++;


                    //become an error on THIS 
                    this.newLine.on('mouseover', () => {
                        document.body.style.cursor = 'pointer';
                        this.strokeWidth(12);
                    });
                   
                    layerLines.add(newLine);                       
                    stage.add(layerLines);
                    stage.add(layer);                       
                }
            }
        }
    })();       
    
});   

}

on the this.strokeWidth(xx); i have en error

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Simple scope bug in your code - newline r=declared as

var newLine

then refered to as

this.newLine

Maybe you made a mistake preparing your code sample to post ?

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!