javascript - jQuery - What is the the difference -
I was checking one of my client's codes and came over it.
$ (document futures fu2 () {$ ("# id2") (function)) .bund ('click', function () {});} foo2 ();} );
What they are doing, attach the event handler inside the function and then call that function.
How does this differ from the following?
$ (document) .ready (function () {$ ("# id1"). Bind ('click', function () {}); $ ("# id2") Bind ('click', function () {});});
This event handlers is directly attached to the $ (document) .ready ()
function.
It works fine in both situations, I was wondering whether there are some performance related issues or something like a work faster or slow or it is a standard way of doing something I know
You can do the difference
Edit:
I would like to give you a an example On failure, there is a need to show a warning with Hello, it is wrong. having had!' You can do these two things: or Solution 1 seems to be the easiest one but ..... Imagine you want to show that error in 1000 places Are working on a huge project with locations now you will need to edit your message at 1000 locations instead of one place. Or when you want to show an HTML popup instead of a warning, imagine changing it. Expect an explanation, it makes sense, please do not tell me.
WARNING ('hello, that was going wrong!');
function show error () {warning ('hello, that was going wrong!'); } ShowError ();
Comments
Post a Comment