Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda