Reputation: 187529
I'm learning OO JavaScript (again). I've written this simple object
function circle(){
this.radius = 4;
}
circle.prototype.area = function(){
this.radius * this.radius * 3.14;
};
var c = new circle();
c.area();
The value returned by c.area()
is undefined
. I guess this can only because this.radius
is not returning 4, why not?
Upvotes: 0
Views: 360
Reputation: 15351
radius
has the value of 4
, but the area
method doesn't return any value.
circle.prototype.area = function(){
return this.radius * this.radius * 3.14;
};
Upvotes: 6