Last active
April 20, 2017 16:15
-
-
Save uladkasach/b45daaa50ee97d460590eabfe7f00b1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////// | |
// Singleton | |
/////////// | |
var car = { | |
desc : null, | |
color : "red", | |
getInfo: function() { | |
return 'A ' + this.color + ' ' + this.desc + '.'; | |
}, | |
drive: function() { | |
//DO SOMETHING | |
}, | |
stop: function() { | |
//DO SOMETHING | |
}, | |
} | |
/////////// | |
// Class w/ Instantiation | |
/////////// | |
function Car (desc) { // Dynamic Properties and Methods | |
this.desc = desc; | |
this.color = "red"; | |
} | |
Car.prototype = { // Static Properties and Methods | |
getInfo: function() { | |
return 'A ' + this.color + ' ' + this.desc + '.'; | |
}, | |
drive: function() { | |
//DO SOMETHING | |
}, | |
stop: function() { | |
//DO SOMETHING | |
} | |
}; | |
//instantiate object using the constructor function | |
var car = new Car('Porsche boxter'); | |
car.color = "blue"; | |
alert(car.getInfo()); //displays 'A blue Porsche boxter. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment