mirror of
https://github.com/cytodev/LightDMMock.git
synced 2024-11-24 23:19:49 +01:00
Replaces Object.watch shim with polyfill by Eli Grey
Fixes issues where objects get hijacked by the shim.
This commit is contained in:
parent
211f9a5e1c
commit
309c9d90c8
@ -418,34 +418,58 @@ window.checkArguments = function(args, length, types) {
|
|||||||
* Object.watch shim *
|
* Object.watch shim *
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
if(!Object.prototype.watch) {
|
/*
|
||||||
Object.prototype.watch = function (prop, handler) {
|
* object.watch polyfill
|
||||||
var oldval = this[prop];
|
*
|
||||||
var newval;
|
* 2012-04-03
|
||||||
var getter = function() {
|
*
|
||||||
|
* By Eli Grey, http://eligrey.com
|
||||||
|
* Public Domain.
|
||||||
|
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// object.watch
|
||||||
|
if (!Object.prototype.watch) {
|
||||||
|
Object.defineProperty(Object.prototype, "watch", {
|
||||||
|
enumerable: false,
|
||||||
|
configurable: true,
|
||||||
|
writable: false,
|
||||||
|
value: function(prop, handler) {
|
||||||
|
var oldval = this[prop],
|
||||||
|
newval = oldval,
|
||||||
|
getter = function () {
|
||||||
return newval;
|
return newval;
|
||||||
};
|
},
|
||||||
var setter = function(val) {
|
setter = function (val) {
|
||||||
oldval = newval;
|
oldval = newval;
|
||||||
newval = handler.call(this, prop, oldval, val);
|
newval = handler.call(this, prop, oldval, val);
|
||||||
return newval;
|
return newval;
|
||||||
};
|
};
|
||||||
|
|
||||||
if(delete this[prop]) {
|
if(delete this[prop]) { // can't watch constants
|
||||||
Object.defineProperty(this, prop, {
|
Object.defineProperty(this, prop, {
|
||||||
get: getter,
|
get: getter,
|
||||||
set: setter
|
set: setter,
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// object.unwatch
|
||||||
if(!Object.prototype.unwatch) {
|
if(!Object.prototype.unwatch) {
|
||||||
Object.prototype.unwatch = function (prop) {
|
Object.defineProperty(Object.prototype, "unwatch", {
|
||||||
|
enumerable: false,
|
||||||
|
configurable: true,
|
||||||
|
writable: false,
|
||||||
|
value: function (prop) {
|
||||||
var val = this[prop];
|
var val = this[prop];
|
||||||
delete this[prop];
|
delete this[prop]; // remove accessors
|
||||||
this[prop] = val;
|
this[prop] = val;
|
||||||
};
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
LightDMMock.watch('default_language', function() {
|
LightDMMock.watch('default_language', function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user