I have a simple prototypal inheritance constructor, which I'm using arrow functions for.
app.Node = function (name, type) {
this.name = name;
this.type = type;
this.children = [];
}
app.Node.prototype = {
addChild: (child)=>{
child._parent = this;
this.children.push(child);
},
removeChild: (child)=>{
this.children.forEach((item, i) => {
if (item === child) {
this.removeChildAtIndex(i);
}
});
},
}
However, due to the nature of this
and arrow functions, the value of this
is undefined
within the prototype methods above. So am I able to use arrow functions in this way? I can't figure out what I'd need to change, other than to use normal function
functions.