Created
April 8, 2015 23:55
-
-
Save pgarciacamou/bb69745d1906b7cdbb89 to your computer and use it in GitHub Desktop.
Default properties without using external libraries using prototype inheritance
This file contains hidden or 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
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