opera.defineMagicFunction()
Description:
This method can be used to override global functions defined by regular scripts in a page.
Parameters:
name: String giving the name of the function to be overridden.implementation: Function to be run in place of the function defined by the page. The function will be passed the following parameters.- A reference to the real function defined by the page.
- The object that would have been referred to by the this keyword in the real function.
- Any parameters that would have been passed to the real function (each is passed as a separate parameter to the magic function).
Syntax:
void defineMagicFunction (<DOMString> name, <Function> implementation)
Example:
window.opera.defineMagicFunction('getLayer', function (oRealFunc, oThis, oParam1, oParam2) {
return oParam1.getElementById(oParam2).style;
});
// This example overrides a function f. If the this object refers to the window object, it returns false.
// Otherwise it just runs the real function instead:
window.opera.defineMagicFunction('f', function (real, thisObject) {
if (thisObject == window) {
return false;
} else {
return real.apply(thisObject, Array.prototype.slice.call(arguments, 2));
}
});About this article
| Published in | Dev.Opera |
|---|---|
| Date | December 6, 2011 |
| Author | Opera Software |
| Tags | extensions API, injected scripts |
| Original | Internet Archive |