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
Line 1: Line 1:
=Angular=
Angular provides a model view controller framework for writing complex Javascript apps: [[Angular]]
* [[Angular/FirstTry]]
* [[Angular/SecondTry]]
=Passing Arguments to Callback Functions=
=Passing Arguments to Callback Functions=


<source lang="javascript">
<pre>

// global variable

// global variable
var allUserData = [];
var allUserData = [];
Line 33: Line 39:
//  name: Rich
//  name: Rich
// speciality: JavaScript
// speciality: JavaScript
</source>
</pre>

Revision as of 09:24, 16 April 2017

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