Mootools extends the “Function” class with an “extend” method making jQuery unusable

北慕城南 提交于 2019-12-24 05:08:05

问题


Mootools extends the "Function" class and adds a new method called "extend" in it. Now jQuery tries to add "extend" function using jQuery.prototype.extend. However since "extend" is already a part of the jQuery object (since jQuery is an object of the Function class) so jQuery.prototype.extend doesn't work. Did anyone come across this conflict while using Mootools and jQuery simultaneously ?

More generically, if a native class like "Function or Array or Object" is extended, do we have a way to revert back to the original definitions ?


回答1:


The only way I can think to do that:

<script type="text/javascript">
    // copy the original function
    var ext = Function.prototype.extend;
    // remove it
    delete Function.prototype.extend;
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> 

<script type="text/javascript">
    // Copy the jQuery version
    var jqext = jQuery.prototype.extend;
    // remove it (for sanity).
    delete jQuery.prototype.extend;

    // reassign the original function.
    Function.prototype.extend = ext;
    // remove the jQuery extend method (now the original Function.extend method)
    delete jQuery.prototype.extend;
    // reassign jQuery's original extend method.
    jQuery.prototype.extend = jqext;
</script>



回答2:


Have you tried jQery.noConflict ? http://api.jquery.com/jQuery.noConflict/



来源:https://stackoverflow.com/questions/4130723/mootools-extends-the-function-class-with-an-extend-method-making-jquery-unus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!