Mootools 扩展了“Function”类,并在其中添加了一个名为“extend”的新方法。现在 jQuery 尝试使用 jQuery.prototype.extend 添加“扩展”功能。然而,由于“extend”已经是 jQuery 对象的一部分(因为 jQuery 是 Function 类的对象),所以 jQuery.prototype.extend 不起作用。
有人在同时使用 Mootools 和 jQuery 时遇到过这种冲突吗?
更一般地说,如果扩展了像“函数、数组或对象”这样的本机类,我们是否有办法恢复到原始定义?
我能想到的唯一方法是:
<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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)