var a = function(){
this.x = function(){alert('apple');}
this.y = function(callback){
if(typeof callback == 'undefined' || callback == null)
alert('argh')
else
callback();
}
}
var foo = function(){alert('blah')};
var x = new a();
x.y(this.x); // why is this one undefined
x.y(foo); // works as expected
here is the jsfiddle link: http://jsfiddle.net/W7FyZ/2/
Why is it undefined when I pass in a object member function? Is there a way to pass a object member function as a callback?
I have just renamed your variable to clear the confusion.
Now, In the execution part:
Above line is assigning function a() variable ‘myA’. So,Functions
x()andy()ofa(),should be called asmyA.x()andmyA.y().