Factory method pattern

by Mohan 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);


757
like
0
dislike
0
mail
flag

You must LOGIN to add comments