public
Created

How to save Model data

  • Download Gist
Prop.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
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;
}
 
};
StorageProp.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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;
}
 
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.