MooTools and jQuery integration

2019-05-14 09:50发布

I am using the code MooTools (1.11) and jQuery (1.2.6). It's working fine when these are separate. While I am integrating Firefox, it throws:

(document).ready(){} is not a function.

Is anything wrong in my concept? What do I do to rectify it?

5条回答
Bombasti
2楼-- · 2019-05-14 10:12
jQuery.noConflict(); 
jQuery(function($){ 

   $works with jQuery here. 
});
$ Works with MooTools here. 

However, that said, I would suggest you ditch the MooTools.

Its complete modification of all object prototypes can cause cause jQuery's functions to randomly and unexplainable cause errors, and on top of that, MooTools' modification of all object prototypes (the Object and Function prototypes are even modified), have, in my experience, resulted in jQuery performing significantly slower than without, simply for MooTools being on the same page.

Additionally, MooTools is 50 KB and jQuery is 25 KB (average numbers, including extensions). Having them both will drastically slow down page load just for the extra data fetch.

A project I was working was having problems with JavaScript performance, and I'm talking really serious slowdowns, in seemingly simple code. We migrated to jQuery, and there was no performance gain until we stopped loading the MooTools when we'd finished migrating the code, and then as soon as we dropped MooTools, the speed came back.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-05-14 10:12

MooTools for jQuery: http://moo4q.com/

jQuery <3 the DOM jQuery is awesome but it's scope is (generally) DOM [manipulation]
MooTools <3 Objects MooTools make working with [javascript] objects huckleberry pie.

查看更多
迷人小祖宗
4楼-- · 2019-05-14 10:26

jQuery and MooTools both use '$' as a shorthand way of calling their main functions. The jQuery team have built in a way to stop this, so you can write something like:

jQuery(document).ready(function(){...});

Instead of

$(document).ready(function(){...});

This will let you use jQuery and any other JavaScript library side by side. Read their docuentation on the subject - Using jQuery with Other Libraries.

查看更多
做个烂人
5楼-- · 2019-05-14 10:31

You can also see the use of .noConlict method of jQuery. I don't know if it'll be usefull in your case...

查看更多
Evening l夕情丶
6楼-- · 2019-05-14 10:36

In addition to sanchothefat said, you really should try to avoid using two such frameworks together because they essentially do the same thing. If you're not gzipping your Javascript, you're probably sending the user at least 150-200k of JavaScript with just the libraries, nevermind the plugins you're using. Almost anything you do in MooTools can be done in jQuery and vice versa. If you look around, you can probably find scripts that do what you're looking for that have been ported both ways.

查看更多
登录 后发表回答