Why is my prototype function not returning the property of the instance?
- by Pydroid
Hi,
I have a simple object in Javascript.
function myClass(x,y) {
this.x = x;
this.y = y;
}
and a prototype function
myClass.prototype.myfunction = function() {
console.log(this.x);
}
and in my main script,
var x = 2; var y = 4;
myinstance = new myClass(x,y);
myinstance.myfunction();
Instead of receiving x, I get undefined instead. Why is that?