Which is best practice, which results in better performance?
UPDATE: jsperf.com reports that (a) is faster @ http://jsperf.com/closure-vs-global-variable
a) using a closure
var obj = {
init: function() {
var self = this;
$('#element').click(function() {
self.clickEvent();
});
},
clickEvent: function() {
this.miscMethod();
},
miscMethod: function() {}
};
b) using the global variable
var obj = {
init: function() {
// removed self=this closure
$('#element').click(this.clickEvent); // simple method handler
},
clickEvent: function() {
obj.miscMethod(); // global variable used
},
miscMethod: function() {}
};