Skip to content

Instantly share code, notes, and snippets.

@dasibre
Created March 5, 2016 21:12
Show Gist options
  • Select an option

  • Save dasibre/9e981657bce4ca7d0ea6 to your computer and use it in GitHub Desktop.

Select an option

Save dasibre/9e981657bce4ca7d0ea6 to your computer and use it in GitHub Desktop.
javascript object creation patterns
Object.defineProperty(newObject,"name", {
value: "Kwame",
writable: false,
enumerable: true,
configurable: true
});
var defineProp = function (obj, key, value) {
var config = {
value: value,
writable: true,
enumerable: true,
configurable: true
};
Object.defineProperties(obj, key, config);
}
//Constructor pattern
function Car( model, year, miles ) {
this.model = model;
this.year = year;
this.miles = miles;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment