Home › Forums › JavaScript › Call function with function parameter › Reply To: Call function with function parameter
December 13, 2015 at 1:59 pm
#235826
Participant
The window represents the JavaScript window object. It’s the global scope for all the JavaScript code that runs in the browser.
Function left
, right
and myFunction
are all in global space. Essentially it’s this:
window.left()
, window.right()
etc…
function myFunction( func ) {
// assign variable fn to window object
var fn = window[func];
// at this point fn = window.right
// we then check if the window.right is a function
if ( typeof fn === 'function' ) {
// if so run it
fn();
}
}
Hope that helps.
Alen