Is it ok to declare same window events multiple times in jQuery?
I have a few elements listening to window resize and scroll events. In order to make the code clear for reading, I declared same window events multiple times in different blocks, like the following...
- $('#foo')...
- $(window).resize(function() {
- $('#foo')...
- });
- // lots of code...
- $('#bar')...
- $(window).resize(function() {
- $('#bar')...
- });
- // and so on..
where I believe generally it should be written as
- $(window).resize(function() {
- $('#foo')...
- $('#bar')...
- });
- // lots of code
- $('#foo')...
- // lots of code
- $('bar')...
My question is, will it make any difference to jQuery performance if I declare window events multiple times?