需要挂钩到javascript函数调用,任何方式都可以这样做? [英] Need to hook into a javascript function call, any way to do this?

查看:143
本文介绍了需要挂钩到javascript函数调用,任何方式都可以这样做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图加入一个加载Facebook新闻源的功能:

I'm trying to hook into a function that loads Facebook's news feed:

UIIntentionalStream.instance && UIIntentionalStream.instance.loadOlderPosts();

是有一种方法让我用自己的JavaScript做到这一点?基本上,我需要进行某种回调 - 当调用该函数时,我希望调用我自己的函数。

Is there a way for me to do this with my own JavaScript? Basically, I need to have some sort of callback - when that function is called, I'd like my own function to be called.

推荐答案

尝试这样的事情:

var old = UIIntentionalStream.instance.loadOlderPosts;
UIIntentionalStream.instance.loadOlderPosts = function() {
    // hook before call
    old();
    // hook after call
};

只需在原始函数调用之前或之后挂钩即可。

Just hook in wherever you want, before or after the original function's call.

这篇关于需要挂钩到javascript函数调用,任何方式都可以这样做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆