Factory method pattern
by Mohan[ Edit ] 2012-09-20 23:08:35
Factory method pattern
Complex = new function() {
function Complex(a, b) {
// ...
}
this.fromCartesian = function(real, mag) {
return new Complex(real, imag);
}
this.fromPolar = function(rho, theta) {
return new Complex(rho * Math.cos(theta), rho * Math.sin(theta));
}
}
var c = Complex.fromPolar(1, Math.pi); // Same as fromCartesian(-1, 0);