3
我在我的常規js中創建了一個名爲startsWith的擴展函數。IE9 this = DispHTMLWindow2在原型函數中
它是這樣的:
String.prototype.startsWith = function (str) {
if (this.indexOf(str) == 0) {
return true;
}
return false;
}
當IE9運行我得到一個錯誤說:「對象不支持屬性或方法‘的indexOf’」。
在調試器中看起來像是DispHTMLWindow2。
任何幫助?
謝謝。
這IE9對我的作品拍攝。 http://jsfiddle.net/sQt5C/ – Gaurav
你打電話過得怎麼樣?聽起來像它被稱爲一種功能,而不是一種方法。 –
聽起來像你沒有傳入字符串。你可以添加一個構造函數檢查來阻止它跳出if(this.constructor!== String)return – Christian