Search code examples
jquerybackbone.jsmarionetteconflict

jQuery.noConflict(true) - Causing Marionette code to break


I have the following code:

    jq1111 = jQuery.noConflict(true);

    (function($, jQuery){
        // bunch of js libraries (backbone, underscore, etc)
        ...
        Marionette.Callbacks = function(){
            this._deferred = Marionette.$.Deferred();
            this._callbacks = [];
        };
        ...
    })(jq1111, jq1111)

I am seeing an error where it's saying $ is undefined in this._deferred = Marionette.$.Deferred();.

I've defined $ in the function and all other instances of $ seem to be working with no issue. Any idea why this is happened or how to get around it please?

Note that using jQuery.noConflict() without "true" works fine, but I've defined jQuery in the new function call so there shouldn't be a difference...

Thank you.


Solution

  • I decided to just change my code to do the following:

    (function($, jQuery){
        // bunch of js libraries (backbone, underscore, etc)
        ...
    })($, jQuery)
    
    jq1111 = jQuery.noConflict(true);
    

    I'm not sure why the standard is to define noConflict() before you define your jQuery, then use your definition in the function. In all honesty it makes a lot more sense to do it this way.