Skip to content

Instantly share code, notes, and snippets.

@mtford90
Created January 17, 2015 12:31
Show Gist options
  • Save mtford90/0c1f01c6a88fc30c7d69 to your computer and use it in GitHub Desktop.
Save mtford90/0c1f01c6a88fc30c7d69 to your computer and use it in GitHub Desktop.
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