[英]JS Using prototype function in prototype
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? 是否可以在其他原型功能中使用原型功能?
您需要像其他任何属性一样将它们作为this
属性来引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.