Skip to content

Instantly share code, notes, and snippets.

@uladkasach
Last active April 20, 2017 16:15
Show Gist options
  • Save uladkasach/b45daaa50ee97d460590eabfe7f00b1c to your computer and use it in GitHub Desktop.
Save uladkasach/b45daaa50ee97d460590eabfe7f00b1c to your computer and use it in GitHub Desktop.
///////////
// 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