Skip to content

Instantly share code, notes, and snippets.

@pgarciacamou
Created April 8, 2015 23:55
Show Gist options
  • Save pgarciacamou/bb69745d1906b7cdbb89 to your computer and use it in GitHub Desktop.
Save pgarciacamou/bb69745d1906b7cdbb89 to your computer and use it in GitHub Desktop.
Default properties without using external libraries using prototype inheritance
function MyConstructor(options){
options = options || {};
// Default properties:
options.__proto__ = {
threshold: 3,
quality: 1
etc: "whatever"
};
// Use case:
this.render = new MyDummyRenderer(options.quality);
}
// Calling the constructor can be as easy as:
var myConstructorInstance = new MyConstructor();
// And you are able to call properties like:
myConstructorIntance.render;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment