Feeds:
Posts
Comments

Posts Tagged ‘not found in object’

One of my colleague using Internet Explorer 10 to emulate IE 8 Standard mode. During calling slice() method for a String object. It shows the error “slice not found in object”.

我有位同事用Internet Explorer 10去模擬IE 8標準模式。在一句指令中,字串物件上執行slice()方法時,卻發生了問題,Internet Explorer顯示”slice not found in object”

This problem in weird since in microsoft website, it stated that string’s slice method is existed in all versions. (http://msdn.microsoft.com/en-us/library/ie/s4esdbwz(v=vs.94).aspx)
這是個奇怪的情況,因為在微軟的網站內寫著所有版本Internet Explorer都有String slice。

In order to avoid any similar problem, I wrote a custom slice() method whenever slice() is not found as default:
為了避免這問題,我寫了一段指令,當發現在字串物件中找不到slice()時,會用一個自訂的slice()方法.

if(typeof String.prototype["slice"]==="undefined"){String.prototype.slice=function(s,e){var l=this.length;return this.substr(s=s<0?l+s:s,typeof e==='number'?(e<0?l+e:e)-s:l-s)}}
Advertisements

Read Full Post »