refer to http://stackoverflow.com/questions/2190850/javascript-create-custom-callback
functionThing(name){
this.name = name;
}
Thing.prototype.doSomething =function(callback, salutation){
// Call our callback, but using our own instance as the context
callback.call(this, salutation);
}
function foo(salutation){
alert(salutation +" "+this.name);
}
var t =newThing('Joe');
t.doSomething(foo,'Hi'); // Alerts "Hi Joe" via `foo`
转载于:https://www.cnblogs.com/webglcn/archive/2012/08/15/2640354.html