开发者

IE9 this = DispHTMLWindow2 inside a prototype's function

开发者 https://www.devze.com 2023-03-20 18:12 出处:网络
I created an extension function called startsWith in my general js. It goes like this: String.prototype.startsW开发者_StackOverflowith = function (str) {

I created an extension function called startsWith in my general js.

It goes like this:

String.prototype.startsW开发者_StackOverflowith = function (str) {
 if (this.indexOf(str) == 0) {
     return true;
 }
 return false;
}

When running in IE9 i get an error saying: "Object doesn't support property or method 'indexOf'".

When looking in the debugger it seems like this is DispHTMLWindow2.

Any help?

Thanks.


You could try the following as taken from this site

String.prototype.startsWith = function(str) 
{return (this.match("^"+str)==str)}

String.prototype.endsWith = function(str) 
{return (this.match(str+"$")==str)}

String.prototype.trim = function(){return 
(this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))}
0

精彩评论

暂无评论...
验证码 换一张
取 消