标签:
回调函数的定义为:传递一个函数A到另一个函数B中,由B调用A,我们就说函数A叫做回调函数。如果没有名称,就叫做匿名回调函数。
function invoke_and_add(a,b){ return a()+b(); } function one(){ return 1; } function two(){ return 2; } invoke_and_add(one ,two);
invoke_and_add(function(){return 1;},function(){return 2;})
int TVPrice(int price) { printf("The price of the TV is %d. \n", price); return 0; } int PCPrice(int price) { printf("The price of the PC is %d. \n", price); return 0; } void Caller(int n, int (*ptr)())//指向函数的指针作函数参数,第一个参数是为指向函数的指针服务的, { //不能写成void Caller(int (*ptr)(int n)) (*ptr)(n); } int main() { Caller(3000, TVPrice); Caller(5000, PCPrice); return 0; }
function lightUp(A, callback){ callback(); A.lightUp(); } function callback(){ B.lightUp(); }
var temp = false; while(!temp){ temp = wait(A.lightUp()); } B.lightUp();
function AlightUp(){ this.trigger(‘done‘); this.do(); } function BlightUp(){ this.do(); }
AlightUp.on(‘done‘,BlightUp);
jQuery.subscribe("done", f2); function f1(){ setTimeout(function () { // f1的任务代码 jQuery.publish("done"); }, 1000); }
jQuery.unsubscribe("done", f2);
f1().then(f2); function f1(){ var dfd = $.Deferred(); setTimeout(function () { // f1的任务代码 dfd.resolve(); }, 500); return dfd.promise; }
标签:
原文地址:http://www.cnblogs.com/qionglouyuyu/p/4607439.html