andrewdavey / cassette

Manages .NET web application assets (scripts, css and templates)
http://getcassette.net
MIT License
534 stars 143 forks source link

setTimeout with lambda causes incorrect minification #483

Open Nagareboshi18 opened 4 years ago

Nagareboshi18 commented 4 years ago

When I use arrow function:

setTimeout(() => this._check(), 1000);

it completely messes up the minified scripts.

My widget that contains that function ends up like this:

NEWS.CheckIfItemExists.prototype,
this._timeout(),
this._timeoutMsg.removeClass("hidden"),
this._loading.addClass("hidden"),

while it should look like this:

NEWS.CheckIfItemExists.prototype={
    init:function(){
        this._check()
    },
    _check:function(){
etc. ........

After commenting out just the arrow fuction: () => things go back to normal.

I managed to find another way of doing the setTimeout:

setTimeout(function () { this._check(); }.bind(this), 1000);

But obviously the arrow function makes the code simpler and it should be just fine with Cassette.