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?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.