Skip to content

Instantly share code, notes, and snippets.

@jiggliemon
Created December 27, 2011 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiggliemon/1525505 to your computer and use it in GitHub Desktop.
Save jiggliemon/1525505 to your computer and use it in GitHub Desktop.
How to save Model data
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;
}
};
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