NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
This library allows any script to override native functions pretty much like OOP languages do. It also supports base/super call, which allows the override function to act like a proxy, i.e., you'll still get the native function result.
It's pretty simple to override a function:
Function.override('aObject.nativeFunction', function(){
doSomething();
});
You can do this multiple times: any subsequent call will override the last override function.
If you need to use the native function inside your override, use the base object:
Function.override('aObject.nativeFunction', function(){
doSomething();
base.nativeFunction.apply(this);
});
If you need to use the original function arguments, or any arguments you receive, you can use the vanilla's arguments
's object:
Function.override('aObject.nativeFunction', function(){
doSomething.apply(this, arguments);
base.nativeFunction.apply(this, arguments);
});
You can restore the native function any time by calling:
Function.restore('aObject.nativeFunction');
This will rollback the function to it's vanilla state, even though the function got overridden multiple times.
Rating: 0