我在使用jQuery和原生JavaScript(而不是 prototype.js)時遇到問題。當使用以下代碼時,jQuery 1.9.1出現錯誤消息:jQuery與原生原型的衝突
Object.prototype.myVeryGreatFunction = function() {
// ...
}
[Error] TypeError: undefined is not a function (evaluating 'U[a].exec(s)')
ft (jquery.min.js, line 4)
wt (jquery.min.js, line 4)
st (jquery.min.js, line 4)
find (jquery.min.js, line 4)
init (jquery.min.js, line 3)
b (jquery.min.js, line 3)
(anonymous function) (read.control.js, line 59)
c (jquery.min.js, line 3)
fireWith (jquery.min.js, line 3)
ready (jquery.min.js, line 3)
H (jquery.min.js, line 3)
當我刪除原型定義時,一切正常。不幸的是,我不能輕易更新jQuery,因爲這是一個CMS的插件,所以爲了兼容性原因它必須使用舊版本。
是否有任何已知的問題或解決方案?
谷歌搜索實際上顯示出我喜歡使用jQuery.noConflict()
和私人功能包裝的解決方案。但如上所述,我沒有使用prototype.js,但原生 JS對象原型。
你能爲我們提供一個小提琴 –
可能的重複[原型對象在JavaScript中斷jQuery?](http://stackoverflow.com/questions/1827458/prototyping-object-in-javascript-breaks-jquery) – Alnitak