Created
January 17, 2015 12:31
-
-
Save mtford90/0c1f01c6a88fc30c7d69 to your computer and use it in GitHub Desktop.
This file contains 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 Something() { | |
_.extend(this, { | |
attr: 1, | |
_extras = {}, | |
__setattr__: function (key, value) { | |
this._extras[key] = value; | |
}, | |
__getattr__: function (key) { | |
return this._extras[key] || 'That attribute doesnt exist yet!'; | |
} | |
}) | |
} | |
var s = new Something(); | |
console.log(s.attr); // 1 | |
console.log(s.x); // 'That attribute doesnt exist yet!' | |
s.x = 2; | |
console.log(s.x); // 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment