jquery - Is it better to use bind() or not in terms of memory savings? -
which 1 of these considered better code , why , better on memory?
say jquery code looks example 1 without bind();
$(document).ready(function(){ $('#somediv').mouseenter(function(){ $('#somediv').fadeto('fast',1); }); $('#somediv').mouseleave(function(){ $('#somediv').fadeto('fast', .5); }); }); or bind() method.
$(document).ready(function(){ $('#somediv').bind({ mouseenter: function(){ $('#somediv').fadeto("fast",1); }, mouseleave: function(){ $('#somediv').fadeto("fast",0.5); ) }) });
there's no difference. different ways of binding event handlers in jquery call same internal function perform binding. here's simplified view of how works:
bind: function(bindings) { (event in bindings) { return this.on(event, bindings[event]); }, mouseenter: function(handler) { return this.on("mouseenter", handler); }, mouseleave: function(handler) { return this.on("mouseleave", handler); } btw, .bind() outdated, although it's not yet deprecated. .on() preferred unless need compatible jquery versions before 1.7.
Comments
Post a Comment