Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Call function with function parameter Reply To: Call function with function parameter

#235826
Alen
Participant

@cutecoder

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