What is the deal with passing a parameter from a function into a setTimeout call? Why is path here returning undefined? And what should I do instead?
$('.curatorSpace').bind('click', function() {
var path = $(this).attr('data-path');
setTimeout(function(path) {
if($('#curatorRibbon').hasClass('ui-draggable-dragging')){return false}
runOverlay(path);
}, 100);
});
You don’t need/must pass anything in there.
pathis a free variable and closured by the anonymous function you pass intosetTimeout. Hence, you can just access it.actually, by declaring
pathas formal parameter of that anonymous function, you’ve overwritten that variable lookup process through the scope chain. Just get rid of that.