I have an object with a method, I want to pass the method as an argument to another function. However the function must know the object associated with the method (or it can't access values assigned to the object after creation).
Is there a way to this without resorting to passing the object/method as a string?
(ex not using: window[function_name];)
function My_Object(name){
this.name = name;
}
My_Object.prototype.My_Method = function(){
alert(this.name);
}
//This is the function that passes the method
function Runner(){
var NewObject = new My_Object('Andre');
test(NewObject.My_Method);//this is where it should break
}
//This is the function that receives and calls the Object's method
function test(func){
func();
}
test(function() { NewObject.My_Method(); })?test(NewObject.My_Method.bind(NewObject));