I was reading the great article about binding and unbinding events (because I am a js beginner using jQuery) on Karl Swedberg’s blog, and I became totally puzzled at this part of the code (simplified for brevity):
function addItemUnbind() { $Add a button but it won't have it's event added; addItemUnbind(); });
Why is it that by putting the same function within itself it doesn’t keep executing into an infinite loop? However, it is used to re-bind the event to the element…!?
Because the call is within an internal function.
E.g. He does some stuff in addItemUnbind() and one of those things is to bind a function to a button click.
This function is then declared e.g. within addItemUnbind() there is:
The code within the braces here isn’t evaluated when addItemUnbind() is called but rather when the click happens.