Javascript custom callback

refer to http://stackoverflow.com/questions/2190850/javascript-create-custom-callback

function
Thing(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`
posted @ 2012-08-15 16:43  webglcn  阅读(188)  评论(0编辑  收藏  举报