Skip to content

Instantly share code, notes, and snippets.

@greggnakamura
Created January 3, 2015 22:14
Show Gist options
  • Save greggnakamura/f8eaf88411c7dd9e0b4a to your computer and use it in GitHub Desktop.
Save greggnakamura/f8eaf88411c7dd9e0b4a to your computer and use it in GitHub Desktop.
Javascript: function example
/* functions */
/* passing a function as a parameter */
var calculate = function (number, paramTwo, fn) {
number = number + 3;
number = number + 1;
number = number * 8;
return fn(number, paramTwo);
};
/* function parameter for 'fooResult' */
function sum (number, paramTwo) {
return number + paramTwo;
}
/* function parameter for 'barResult' */
function product (number, paramTwo) {
return number * paramTwo;
}
var foo = 2,
bar = 3;
var fooResult = calculate (foo, 2, sum);
var barResult = calculate (bar, 2, product);
console.log('foo: ' + fooResult);
console.log('bar: ' + barResult);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment