Reputation: 181
Hey i'am writing a little object :
function Point(x, y) {
this.x = x;
this.y = y;
this.angle = Math.sqrt(x * x + y * y);
this.radius = Math.atan(y / x);
};
Point.prototype = {
constructor: Point,
calculateRadius: function(x, y) {
return Math.sqrt(x * x + y * y);
},
calculateAngle: function(x, y) {
return Math.atan(y / x);
},
cartToRad: function(x, y) {
this.radius = calculateRadius(x, y);
this.angle = calculateAngle(x, y);
}
};
var coords = new Point(0, 0);
coords.cartToRad(5, 0.523);
And that throw an error:
ReferenceError: calculateRadius is not defined.
Is it possible to use prototype functions in other prototype functions?
Upvotes: 1
Views: 46
Reputation: 887275
You need to reference them as properties of this
, just like any other property.
Upvotes: 2