Q: call inner function from global function to display alert in javascript I have a javascript code and want to extend this code now. how can I write a makeAMessenger function in global scope so that it triggers when user clicks document and alert below message
THIS. IS. SPART.

currently I have following code.
CODE HERE

A: Do you mean this ?
function makeAMessenger(madness, sparta) {
   return madness.bind(sparta);
}


A: have a solution here  and you don't need to pass variable along, it can be accessed in function.
      function makeAMessenger(madness) {
        return madness;
    }


A: You can use Function#apply() or Function#call() to bind this.
http://jsfiddle.net/QfNbp/
