1

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?

thefourtheye
241k53 gold badges466 silver badges505 bronze badges
asked Mar 19, 2015 at 17:34

1 Answer 1

2

You need to reference them as properties of this, just like any other property.

answered Mar 19, 2015 at 17:34
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.