I have this code:
pPoint = function(x,y){
this.x = x || 0;
this.y = y || 0;
}
pPoint.prototype = {
constructor:pPoint,
add:function(){
return this.x+this.y;
}
}
And if I do:
a = new pPoint(10,20)
console.log(a.add());
Works as expected (returns 30).
However if I do this:
Array.prototype = {
abcd:function(){
console.log("bla bla testing");
}
}
And then do this:
b = new Array();
b.abcd();
It does not work... why?
I know that if I do this works fine...
Array.prototype.abcd:function(){
console.log("bla bla testing");
}
}
I just dont get why the preivous one works on my pPoint and not in Array...
pPoint.prototype={}) will have pPoint.prototype.constructor point to Object instead of pPoint. constructor should point to the right function, if you're not using it and you're not expecting other people to extend your code this should not be a problem though but it's worth mentioning.