Javascript: Difference between revisions
From charlesreid1
(Created page with "=Passing Arguments to Callback Functions= <source lang="javascript">
// global variable var allUserData = []; // generic logStuff function that prints to console function lo...") |
No edit summary |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
See also: [[:Category:Javascript]] | |||
=Angular= | |||
Angular provides a model view controller framework for writing complex Javascript apps: [[Angular]] | |||
* [[Angular/FirstTry]] | |||
* [[Angular/SecondTry]] | |||
* [[AngularPelican]] | |||
* [[:Category:Angular]] | |||
=Passing Arguments to Callback Functions= | =Passing Arguments to Callback Functions= | ||
< | <pre> | ||
// global variable |
// global variable | ||
var allUserData = []; | var allUserData = []; | ||
| Line 33: | Line 43: | ||
// name: Rich | // name: Rich | ||
// speciality: JavaScript | // speciality: JavaScript | ||
</ | </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