Question about the prototype / Mootools

So, I have a page that uses both Prototype scripts and Mootools AJAX scripts.

Prototype has a lot of Mootools, so I wonder if Prototype has a function similar to jQuery $j = jQuery.noConflict();that I can use to override the $ alias for the prototype?

Thanks!

+5
source share
2 answers

There is no conflict mode in the latest version of MooTools. Unfortunately, Prototype does not do this, which means that it $must be bound to Prototype.

To enable safe dollar mode, upgrade your MooTools version and make sure you enable MooTools after Prototype.

<script type="text/javascript" src="prototype.js" />
<script type="text/javascript" src="mootools.js" />

$ Prototype. MooTools $ document.id.

// Before
var X = new Class({
    initialize: function(element){
        this.element = $(element);
    }
});


// After
var X = new Class({
    initialize: function(element){
        this.element = document.id(element);
    }
});

:

(function(){

    var $ = document.id;

    this.X = new Class({
        initialize: function(element){
            this.element = $(element);
        }
    });

})();

Dollar MooTools:

http://mootools.net/blog/2009/06/22/the-dollar-safe-mode/

+8

:

<script src='mootools.js'></script>
<script>$moo = $; delete ($);</script>
<script src='prototype.js></script>



<script>

(function ($){


//here you can use $ of moo tools

})($moo);


//here you can use $ of prototype


</script>
+3

All Articles