user2146441
user2146441

Reputation: 228

Access anonymous functions in the console

If my javascript is already running, and I have a function like this in the code:

var myObject= {
    foo: function() {
    }
};

I can log calls to the function and get an alert in the console when it's called by submitting this:

myObject.foo = function(c) {alert('Called!');}

How can I do the same if the javascript method is set up as follows:

! function(a) {
    a.SOMEOBJ= function() {
        this.varA= {}, this.varB = {}
    };
    var b = a.SOMEOBJ.prototype;
    b.bar= function() {
        return 1
    }, b.foo= function(b) {
       //Do some calc
       //I want to add an alert here. . .
    }
}(ANOTHEROBJ);

What's this type of method called and how can I add a line to it so that I get an alert in the Developer tools console when it's called?

Upvotes: 0

Views: 234

Answers (1)

Legends
Legends

Reputation: 22702

I really don't know what you are trying, perhaps this might help you:

var x={};

(function(a) {
  // alert(a.ich);
    a.SOMEOBJ =  {
        varA: {}, varB : {}
    };
    var b = a.SOMEOBJ;

    b.bar= function() {
        return 1;
    };

    b.foo= function(b) {
       alert(b);
    };

})(x);

x.SOMEOBJ.foo("hi");

Upvotes: 1

Related Questions