how to pass a callback function in javascript code example
Example 1: callback function js
function greeting(name) {
alert('Hello ' + name);
}
function processUserInput(callback) {
var name = prompt('Please enter your name.');
callback(name);
}
processUserInput(greeting);
Example 2: javascript pass this to callback
makeHTTPRequest('GET', 'http://youramazingapi/money_makers.php').then(function(data){
this.shakeThose.push(data);
}.bind(this));
Example 3: how to pass callback function in javascript
function functionOne(x) { alert(x); }
function functionTwo(var1, callback) {
callback(var1);
}
functionTwo(2, functionOne);