Can anyone explain to me what is going here?
I have been learning node and callbacks and I am kind of getting the concept but can use some more details.
So in function "myCallback" there is a log to console but in "usingItNow" there is no log to console and the result are "from myCallback From Using it" in the console.
How is it I do not need something like return in usingItNow?
Is this a proper representation for usingItNow if it were not a callback? var usingItNow = 'From Using it'
Can someone post some links to some good tuts?
Is usingItNow proper camelcase or should it be usingItnow?
var myCallback = function(data) {
console.log('from myCallback ' + data);
};
var usingItNow = function(callback) {
callback('From Using it');
};
usingItNow(myCallback);
In your code: usingItNow(myCallback);
You are invoking the function usingItNow
and passing it function myCallback
.
Inside usingItNow
you are executing your parameter callback
by doing this callback('From Using it')
you are essentially doing myCallback('From Using it')
because callback
is equal to myCallback
.
You don't need to return anything because myCallback
is doing the logging.
Your camel case is fine.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments