如何修改本机Javascript对象的(原型?)方法?
有它们的例子吗?您可以在上阅读,下面的脚本在javascript的字符串原型中添加了一个contains方法,类似地,您可以根据需要添加更多的方法 用法 原型法如何修改本机Javascript对象的(原型?)方法?,javascript,Javascript,有它们的例子吗?您可以在上阅读,下面的脚本在javascript的字符串原型中添加了一个contains方法,类似地,您可以根据需要添加更多的方法 用法 原型法 为便于将来参考,请不要在all-caps中键入您的问题。您的链接是关于XmlHttpRequest的:s var myName = "ZainShaikh"; if (myName.contains("zain", true)) { // this condition will be true, because of ignorecas
为便于将来参考,请不要在all-caps中键入您的问题。您的链接是关于XmlHttpRequest的:s
var myName = "ZainShaikh";
if (myName.contains("zain", true)) { // this condition will be true, because of ignorecase parameter
alert('yuppie, this is my name.');
}
else {
alert('awww, this is not my name.');
}
String.prototype.contains = function(value, ignorecase) {
if (ignorecase) {
return (this.toLowerCase().indexOf(value.toString().toLowerCase()) != -1);
}
else {
return this.indexOf(value) != -1;
}
};