HTML and CSS Reference
In-Depth Information
if (typeof r != "number" || r<=0){
throw new TypeError("radius should be > 0");
}
_radius = r;
},
get: function () {
return _radius;
}
}
});
circle.radius = radius;
return circle;
}
Circle.prototype = Object.create(Circle.prototype, {
diameter: {
get: function () {
return this.radius * 2;
},
configurable: false,
enumberable: true
},
circumference: { /* ... */ },
area: { /* ... */ }
});
This constructor can be used like any other, and even makes sense with
instanceof . Listing 8.12 shows a few uses of this constructor.
Listing 8.12 Using the hybrid Circle
TestCase("CircleTest", {
"test Object.create backed constructor": function () {
var circle = new Circle(3);
assert(circle instanceof Circle);
assertEquals(6, circle.diameter);
circle.radius = 6;
assertEquals(12, circle.diameter);
 
Search WWH ::




Custom Search