Created
October 10, 2016 23:44
-
-
Save Sysetup/7cfd8b018175d8d09c7d61d070984f19 to your computer and use it in GitHub Desktop.
Basic callback examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var l = 5, | |
b = 5; | |
function sayHello(greeting){ | |
greeting(function(){ | |
return 'Hello world' | |
}); | |
} | |
function area1(x,y,callback){ | |
callback(function(){ | |
return (x*y); | |
}); | |
} | |
function area2(x,y,callback){ | |
callback( | |
{ | |
area:function(){ | |
return (x*y); | |
} | |
} | |
) | |
} | |
function area3(x,y,callback){ | |
callback( | |
function(){ | |
console.log ('Ready: ' + x*y); | |
} | |
) | |
} | |
sayHello(function (greeting) { | |
console.log(greeting()); | |
}); | |
area1(l,b,function(returned){ | |
console.log('Ready: '+ returned()); | |
}); | |
area2(l,b,function(returned){ | |
console.log('Ready: '+ returned.area()); | |
}); | |
area3(l,b,function(returned){ | |
returned(); | |
}); | |
//Callback: Calling a function having as parameter other function. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment