Javascript: Difference between revisions
From charlesreid1
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 7: | Line 7: | ||
* [[Angular/SecondTry]] | * [[Angular/SecondTry]] | ||
* [[AngularPelican]] | * [[AngularPelican]] | ||
* [[:Category:Angular]] | |||
=Passing Arguments to Callback Functions= | =Passing Arguments to Callback Functions= | ||
| Line 43: | Line 44: | ||
// speciality: JavaScript | // speciality: JavaScript | ||
</pre> | </pre> | ||
[[Category:Javascript]] | |||
Latest revision as of 09:28, 16 April 2017
See also: Category:Javascript
Angular
Angular provides a model view controller framework for writing complex Javascript apps: Angular
Passing Arguments to Callback Functions
// global variable
var allUserData = [];
// generic logStuff function that prints to console
function logStuff (userData) {
if ( typeof userData === "string")
{
console.log(userData);
}
else if ( typeof userData === "object")
{
for (var item in userData) {
console.log(item + ": " + userData[item]);
}
}
}
// A function that takes two parameters, the last one a callback function
function getInput (options, callback) {
allUserData.push (options);
callback (options);
}
// When we call the getInput function, we pass logStuff as a parameter.
// So logStuff will be the function that will called back (or executed) inside the getInput function
getInput ({name:"Rich", speciality:"JavaScript"}, logStuff);
// name: Rich
// speciality: JavaScript