Here is code.
Everything works fine.
Now there is a need for function
second to call function
first. Try this and it will fail.
One way to fix this problem is to hardcode value
foo inside the
second function. Following code works.
Above code works but hardcoding the value of
foo inside the object literal is not good. A better way would be to replace the hardcoded name with
All is good.
second. Now this method would return another function.
Also note that in order to invoke the returned function I have double
()() at the end.
Above code does not work. It did not work because
this has changed. Now
second function refers to the global object rather than referring to the
Fix is simple. In the function
second store the value of