Created
December 27, 2011 23:52
-
-
Save jiggliemon/1525505 to your computer and use it in GitHub Desktop.
How to save Model data
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
var ModelMixin = { | |
get: function ( key , args ) { | |
var isFn = (typeof this[key] === 'function'); | |
return isFn? this[key].apply(this,args): this[key] ; | |
} | |
,set: function ( key, value ) { | |
if(typeof key === 'string') { | |
this[key] = value; | |
return value; | |
} | |
for(i in key) { | |
this.set(i,key[i]); | |
} | |
return key; | |
} | |
}; |
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
var ModelMixin = { | |
_storage: {} | |
,get: function ( key , args ) { | |
var isFn = (typeof this[key] === 'function'); | |
return isFn? this[key].apply(this,args): this._storage[key] ; | |
} | |
,set: function ( key, value ) { | |
var context; | |
if(typeof key === 'string') { | |
context = (typeof this[key] !== 'undefined') ? this : this._storage; | |
context[key] = value; | |
return value; | |
} | |
for(i in key) { | |
this.set(i,key[i]); | |
} | |
return key; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment