1

I tried to run the bundle of MVC4 on javascript files that contain the following function:

$.fn.ApplyBehavior = function (behaviors) {
    var fns = behaviors.split(",");
    var $t = $(this);
    $.each(fns, function (i, o) {
        try {
            var callfn = eval(o);
            if (typeof callfn == 'function') {
                callfn.call($t);
            }
        } catch (e) {
            // faill silently
            console.log(o);
            console.log(e.stack);

        }
    });
    return this;
}

the produced result from the bundle looks like this:

$.fn.ApplyBehavior = function(n) {
    var t = n.split(","), i = $(this);
    return $.each(t, function(i, o) {
        try {
            var callfn = eval(o);
            typeof callfn == "function" && callfn.call(i)
        } catch (e) {
            console.log(o), console.log(e.stack)
        }
    }), this
},

The problem appears from the use of "i" in the output result, I already use "i" inside the "each" loop, so obviously the clash is in calling a function with "i" as the context

I am using the lastest NuGet package of optimization (1.1.0-Beta1), and the usual Bundle code:

bundle = new ScriptBundle("~/scripts/uijs").Include("~/js/ui.web.js");
bundles.Add(bundle);

Am I doing anything wrong? Why isn't it pre-detecting the use of "i"? If this is a bug, how do I report it?

Ayyash
  • 4,257
  • 9
  • 39
  • 58

1 Answers1

1

It's probably because you are using comments inside your code (// faill silently). Sometimes bundles generate errors when you do that.

Gabriel
  • 887
  • 10
  • 22
  • It always seems to be a problem with comments... I was getting errors where ASP.NET put 2 .js files together. The line `//# sourceMappingURL=underscore-min.map;/*` gave errors because the comment block starter `/*` was getting commented out. – AlbatrossCafe Nov 02 '15 at 18:18