Last active
August 29, 2015 14:16
-
-
Save fleon/ffc92efbd64ec8ab0b13 to your computer and use it in GitHub Desktop.
Tell me when this updates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//javascript: | |
function observeFn(obj, fnName, before, after) { | |
var originalFn = obj[fnName], | |
noop = function () {}; | |
before = typeof before === 'function' ? before : noop; | |
after = typeof after === 'function' ? after : noop; | |
obj[fnName] = function () { | |
var args = [].slice.call(arguments); | |
before({ | |
args: args, | |
context: this | |
}); | |
var retval = originalFn.apply(this, args); | |
after({ | |
retval: retval, | |
args: args, | |
context: this | |
}); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//javscript: | |
function observeProp(obj, prop, fn) { | |
var val = obj[prop]; | |
Object.defineProperty(obj, prop, { | |
configurable: true, | |
enumerable: true, | |
get: function () { | |
return val; | |
}, | |
set: function (_val) { | |
val = _val; | |
fn(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment