jquery - JavaScript calling a function without parenthesis -


A few weeks ago I was able to dynamically add the button of an HTML dom object to a dynamically, which has its own .on (click on 'click). Use the handler, and e.stop promotion to prevent these new baby elements from firing incidents.

The strange thing I did was call the function without any bracket. I do not know why I did this or why it works, or why it does not work when I give brackets. I want to know that I am doing something temporarily and do not design (and now I will add a comment for it).

Like:

  // Container is the basic element / var button collects buttons with 'button' $ ('container'). ('Click', function () {$ (button) .appendTo ($ (this)). FadeIn (500) .find ('button.). Click (table button);}); Function table button (e) {e.stopPropagation (); // do stuff}  

I do not understand why I did not write the column to call, there is no dispute or why it works completely. E syntax

  .find ('.button'). ('Click', function (e) {tableButton (e);});  

But then it does not work.

Any help appreciated!

This works because you are passing the function to handle the click instead of calling the function () ()) Example:

  var testFunction = function (msg) {warning}; } Var function caller = function (functionToCall) {functionToCall ('hello!'); } Function caller (testfunction);  

The function passes message logic for testFunction (), but we only implement the function Caller (without argument)

for that part Does not work, instead of tablebutton () see the table named button () T


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -