I have this feature in CoffeeScript
render: -> _.each @$elements, ($el) => if $el[0].id is 'tabs-div' emptySlate = "<div class='js-empty-slate' style='padding:40px;'><h3>no data available</h3><div>" @setEmptyPlacholde($el, emptySlate) return @setEmptyPlacholde($el) setEmptyPlacholde: ($el, emptySlate)-> emptySlateHTML = emptySlate or "<h3 class='js-empty-slate'>no data available</h3>" if $el.hasClass('mobile-os-con') or $el.hasClass('time-of-visit-con') or $el.hasClass('gender-visit-con') or $el.hasClass('time-redemption-sales-con') or $el.hasClass('gender-redemption-con') $el.children().hide() else $el.empty() $el.append emptySlateHTML
$ elements is a jQuery variable that uses an array as follows:
$elements: [ $("#tabs-div") $("#visits-male") $("#visits-female") $("#days-of-visits") $(".time-of-visit-con") ]
When I used the RequireJS r.js optimizer that uses Uglify , the generated mini-code looks like this:
render:function(){var e=this;return _.each(this.$elements,function(t){var n;if(t[0].id==="tabs-div"){n="<div class='js-empty-slate' style='padding:40px;'><h3>no data available</h3><div>",e.setEmptyPlacholde(t,n);return}return e.setEmptyPlacholde(t)})}
In the previous abbreviated code, $el became t .. Thus, it refused to execute the $el element as jQuery in the product.
This is a problem, but I do not know why this is happening. Can someone explain why this is happening to me, thanks.
Update: Minimized code was not a problem, but the script was executed before the nodes in the array loaded correctly, however I call the function after the document is ready , which means that the DOM must be fully loaded.
Hint: I put the script tag on this and it works correctly when the code is not reduced.