"this" property is undefined
ebihimself opened this issue · comments
I tried to implement the object orient of the main.js as below:
class Hello{
templateBlock2
constructor(){
flowy($("canvas"), this.drag, this.release, this.snap)
}
...
drag = (block) => {
block.classList.add("blockdisabled");
this.tempblock2 = block;
}
}
but I receive the error because this is not in the callback scope:
cannot set the property this of undefined
Is there any way that I can pass "this" property to the callbacks?
try replacing arrow functions with normal functions that should help.
drag(block) {
block.classList.add("blockdisabled");
this.tempblock2 = block;
}
I don't think that it has something to do with the arrow function as I think the "this" keyword is not defined in the flowy.min.js as I pass the object of the drag method to the flowy. and the method is trying to find the property there.
Update
The change you mentioned didn't fix.
drag(block) {
block.classList.add("blockdisabled");
this.tempblock2 = block;
}