Created
March 5, 2016 21:12
-
-
Save dasibre/9e981657bce4ca7d0ea6 to your computer and use it in GitHub Desktop.
javascript object creation patterns
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
| 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