/*
Factory method --- Factory function that creates and returns objects of a specific type ( factory function )
*/
function createCar(color,doors,mpg){
var tempCar = new Object;
= color;
= doors;
= mpg;
= function(){
alert( + " " + );
}
return tempCar;
}
/*
Constructor method --- The constructor looks like a factory function
*/
function Car(color,doors,mpg){
= color;
= doors;
= mpg;
= function(){
alert();
};
}
/*
Prototype method ----- Using the prototype property of the object, you can regard it as the prototype on which a new object depends.
*/
function Car(color,doors,mpg){
= color;
= doors;
= mpg;
= new Array("nomad","angel");
}
.showCar3 = function(){
alert();
};
/*
Mixed constructor/prototype method--- Use constructor to define all non-function properties of an object, and use prototype to define the function properties of the object (method)
*/
function Car(sColor, iDoors, iMpg) {
= sColor;
= iDoors;
= iMpg;
= new Array("Mike", "Sue");
}
= function () {
alert();
};
/*
Dynamic Prototype Method--Define non-functional properties within the constructor, while function properties are defined using prototype properties. The only difference is the position given to the object's method.
*/
function Car(sColor, iDoors, iMpg) {
= sColor;
= iDoors;
= iMpg;
= new Array("Mike", "Sue");
if (typeof Car._initialized == "undefined") {
= function () {
alert();
};
Car._initialized = true;
}
} //This method uses the flag ( _initialized ) to determine whether any method has been assigned to the prototype.