For example, I’m building a queue application in ember that’s based off of the queue in the Javascript Road Trip course from Code School if anyone is familiar.
Here’s an example function I’m using:
function buildTicket(allRides, passRides, pick) {
if (passRides[0] == pick) {
var pass = fastAvail.shift();
return function( ) { alert("Quck! You've got a pass to " + pass + "!");
}
}
My question is, why should I return an anonymous function expression over simply returning an alert() ?
function buildTicket(allRides, passRides, pick) {
if (passRides[0] == pick) {
var pass = fastAvail.shift();
return alert("Quck! You've got a pass to " + pass + "!");
}
What is the benefit of returning a function?