javascript - What are the pros and cons of calling jQuery functionality via these 2 different methods? -
I'm trying to understand the difference between these 2 methods of javascript / jQuery functions (if any) I am / P>
Method 1, in then Method 2, In All advice appreciated. The There is no big advantage in writing, the advantage of method 1 is that if you want to attach the same function to different events and / or with different elements such as In short, I do not get the benefit in method 2, while I look at method 1. document.ready () :
$ ('body'). ('Click', 'a.popup', pop up);
function popup () {$ (this) // do something}
document.ready () :
popup (); Then click
function popup () {$ ("a.popup") (function (e) {// do something here}) ; }
popup function in method 2 is called only once, otherwise you are equal Functions
onclick often attach, what you probably do not want is the
popup function body directly in
document.ready () . .
onclick ,
onmousemove etc. In this way you will not have to type the body of the function twice.
Comments
Post a Comment