Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Implicit-override in Javascript

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Thu Mar 28, 2019 4:03 pm    Post subject: Implicit-override in Javascript Reply with quote

I'm no Javascript expert, so I'm hoping someone here might have suggestions.

I'm developing a chrome extension and need to access several properties defined inside an external script (that's running concurrently with mine).

The original script defines an click listener for button like so:

Code:
   
(function() {
    ...
    var config = getUserConfig(...);
    ...
    function begin(config) {
        // Initialize stuff here
    }
    ...
    $("#button").click(function() {
        begin(config);
     });
 })();


The original listener has access to a config property in it's scope. I need to access that property in my code, and I am trying to get a reference to it somehow. Notice that the begin() function takes the config property as a parameter.

I am trying to get a reference to config by overriding begin(). I define my own begin method, then I replace the old click listener with a new one that, binds the old click listener to the current scope, and then calls the old click listener, in hopes that the old click listener calls the overridden version of begin (I really hope that made sense).

Code:
   
$.each($._data($("#button")[0], "events"), function(i, event) {
        $.each(event, function(j, h) {
            if (i == "click") {
                var oldHandler = h.handler;

                h.handler = function() {
                    begin = function(config) {
                        console.log("new begin() called");
                        console.log(config);
                    }

                    var newFunc = oldHandler.bind(this);
                    newFunc();
                }
            }
        });
 });


The old handler still calls the old begin() function. I've tried a bunch of other techniques as well, but I haven't had any success. I set a breakpoint in Chrome Dev Tools and followed the stack trace. When I step into newFunc(), it still calls the old begin() function.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites