I need help understanding the fundamental difference between a closure and the bind()
function in Javascript. I have tried .bind for setting this
scope and used closure to get the scope.
- What is the fundamental difference between the
bind()
function and a closure in JS? - In which scenario should the
bind()
funciton be used and in which scenario should a closure be used?
Here is the code. I'm using ul
as a closure in JS. Can I do this using the bind()
function?
ul.find("li").each(function(a, ele) {
$(ele).attr("tabindex", options.items[a].tabindex);
$(ele).on("focusout", function () {
setTimeout(function (ul) {
$activeElement = $(document.activeElement);
//ul.find("li").indexOf($activeElement) < 0 ? $(ul).focus() :"";
debugger;
}(ul), 1000);
});
});