Skip to content

Instantly share code, notes, and snippets.

@milcktoast
Created December 17, 2012 17:49
Show Gist options
  • Save milcktoast/4320312 to your computer and use it in GitHub Desktop.
Save milcktoast/4320312 to your computer and use it in GitHub Desktop.
set : function (key, val, trigger) {
var i;
if (typeof key === "string") {
if (this.__data[key] !== val) {
if (this['set_' + key]) {
val = this['set_' + key](val);
}
else {
this.__data[key] = val;
}
}
else {
trigger = false;
}
if (trigger !== false) {
this.trigger('change-' + key, key, val);
if (!this.__isChanging) {
this.trigger('change', key, val);
}
}
return val;
}
else {
this.__isChanging = true;
for (i in key) {
this.set(i, key[i], val);
}
this.__isChanging = false;
if (trigger !== false) {
this.trigger('change', key);
}
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment