So I have this code from one of the examples from class.
The method we created is the point.new method.
Point.prototype.toString = function() {
return "(" + this.x + "," + this.y + ")";
};
Point.new = function(x,y) {
var newObj = Object.create(this.prototype);
this.call(newObj, x,y);
return newObj;
};
What I don't understand is why we don't need to declare the method as
point.prototype.new = function(){}
(in fact it wont compile when i do that) however for the
point.prototype.toString(){}
method it is necessary. In both cases we are adding a new method to the point object, so how come one method is being called on just point and the other is being called on point.prototype (I believe this points to object?)
I'm not sure what rule this falls under, but i remember looking at the "adding property to prototype rule" here.
but in this case point is not a prototype since it has no instances right?