Skip to content

Instantly share code, notes, and snippets.

@arv
Last active August 29, 2015 14:17
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 arv/b767ffb8161f1ad4051f to your computer and use it in GitHub Desktop.
Save arv/b767ffb8161f1ad4051f to your computer and use it in GitHub Desktop.
createPropertyAccessor: function(name, ignoreWrites) {
var proto = this.prototype;
var privateName = name + '_';
var privateObservable = name + 'Observable_';
Object.defineProperty(proto, name, {
get: function() {
var observable = this[privateObservable];
if (observable)
observable.deliver();
return this[privateName];
},
set: function(value) {
if (ignoreWrites) {
return;
}
var observable = this[privateObservable];
if (observable) {
observable.setValue(value);
return;
}
var oldValue = this[privateName];
this[privateName] = value;
this.emitPropertyChangeRecord(name, value, oldValue);
},
configurable: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment