我想知道jQuery中的原型是什麼意思?我通常找到關於「Prototype」的信息 - 框架 - 但這裏是jQuery中的「原型」......?你能告訴我什麼時候最好使用它嗎?jQuery fn中的「prototype」? + jQuery中的普通的JavaScript代碼函數?
另外,你能告訴我:爲什麼我們在jQuery插件中使用「普通javascript」代碼而不是jQuery代碼,就像在這個例子中那樣?這是一個快速的問題?
這裏是我的例子:(一個twitter的插件)
感謝您的回答!
$.each(data, function(i, item) {
holder.append("<p>"+item.text.makeLinks()+"</p>");
});
//...further in the code
String.prototype.makeLinks = function() {
return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(str) {
return str.link(str);
});
};
不錯!非常感謝,現在有意義 – Paul 2011-04-23 23:02:26
+1它也幫助了我,謝謝馬特! :-) – fiberOptics 2013-05-20 03:15:49