触发即将被替换的对象的方法
给定这个 var:
somevar = {dothis: function(){console('yay')}};
如果我想劫持它,我想我会做类似的事情:
tempvar = somevar;
somevar = function(){ console.log('yoink'); tempvar();};
但是如果我知道 var 将在 60 秒内重新定义,并且我想在 65 秒内劫持它,我该怎么做这样做吗? setTimeout 不会立即解析该函数,然后引用旧的被劫持的函数吗?
提前致谢。
Given this var:
somevar = {dothis: function(){console('yay')}};
If I want to hijack it, I would think i'd do something like:
tempvar = somevar;
somevar = function(){ console.log('yoink'); tempvar();};
But if I know that the var is going to be redefined in 60 seconds, and I want to hijack it in 65 seconds, how do I do that? Wouldn't a setTimeout parse the function immediately, and then refer to the old hijacked function?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的事情:
演示: http://jsfiddle.net/MDLZt/
Try something like this:
demo: http://jsfiddle.net/MDLZt/