我想知道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