T
tai
Hi.
I'm looking for a way to define a function that's only effective inside
specified function.
Featurewise, here's what I want to do:
bar_plugin_func = function() { ...; setTimeout(...); ... };
wrap_func(bar_plugin_func);
bar_plugin_func(); // calls custom "setTimeout"
So while plugin developer thinks s/he's calling top-level function,
I want to hook it by somehow injecting local variable with the same
name.
Simply doing something like
;(function() { setTimeout = function() { ...my custom implementation
})();
is not ideal, as that'll taint global scope. Actually, I can live with
that for now,
but it's my technical interest to find a way to define it locally.
- http://www.unix.org.ua/orelly/web/jscript/ch11_05.html
So how can I manipulate "transient properties of the function object
itself"?
Thanks in advance.
I'm looking for a way to define a function that's only effective inside
specified function.
Featurewise, here's what I want to do:
bar_plugin_func = function() { ...; setTimeout(...); ... };
wrap_func(bar_plugin_func);
bar_plugin_func(); // calls custom "setTimeout"
So while plugin developer thinks s/he's calling top-level function,
I want to hook it by somehow injecting local variable with the same
name.
Simply doing something like
;(function() { setTimeout = function() { ...my custom implementation
})();
is not ideal, as that'll taint global scope. Actually, I can live with
that for now,
but it's my technical interest to find a way to define it locally.
From the quote in following reference, it says:
- http://www.unix.org.ua/orelly/web/jscript/ch11_05.html
Variable Scope
We saw above that top-level variables are implemented as properties of the current window
or frame object. In Chapter 6, Functions, we saw that local variables in a function are
implemented as transient properties of the function object itself.
So how can I manipulate "transient properties of the function object
itself"?
Thanks in advance.