I'm trying to hook into a function that loads Facebook's news feed:
UIIntentionalStream.instance && UIIntentionalStream.instance.loadOlderPosts();
on Facebook.com.
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.
loadOlderPosts = function() { // hook before call old(); // hook after call }; Just hook in wherever you want, before or after the original function's call.
Javascript Function call() The JavaScript Function call() method calls a function with a given this value and arguments provided individually. The call() method calls a function by passing this and specified values as arguments.
The call() allows for a function/method belonging to one object to be assigned and called for a different object.
A more complete method will be:
var old = UIIntentionalStream.instance.loadOlderPosts;
UIIntentionalStream.instance.loadOlderPosts = function(arguments) {
// hook before call
var ret = old.apply(this, arguments);
// hook after call
return ret;
};
This makes sure that if loadOlderPosts
is expecting any parameters or using this, it will get the correct version of them as well as if the caller expects any return value it will get it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With