The Factory/Constructor Pattern
2010-02-16 Leave a Comment
Code your constructors defensively by checking whether or not it was called with the new operator:
function Circle (color, radius) {
if (! (this instanceof arguments.callee)) {
return new arguments.callee(color, radius);
}
this.color = color;
this.radius = radius;
}
Advertisement