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?

0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.