看板 Ajax 關於我們 聯絡資訊
小弟為了能讓 ie8可支持array新的function如map,filter... if (!Array.prototype.forEach) { Array.prototype.filter = function(callback/*, thisArg*/) {.... 可是當我作in例舉的時候 會把這些function也例舉出來 例如 for(var key in [1,2,3]) { console.log(key); } 0,1,2,map,filter 是不是這樣自已加的function就不能用in這個東西?除非要自已過濾? 不然就無解? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.160.2.183 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1609923682.A.EA3.html
mrbigmouth: 用Object.defineProperty給prototype加filter方法 01/07 10:45
mrbigmouth: 然後加上enumerable: false 01/07 10:45
mrbigmouth: 欸 ie8的defineProperty只能用在DOM上? 01/07 10:47
mrbigmouth: https://github.com/es-shims/es5-shim 參考一下 01/07 10:49
brianwu1201: Script/Reference/Global_Objects/Object/hasOwnProp 01/07 11:18
brianwu1201: erty 01/07 11:18
brianwu1201: 關鍵字 hasOwnProperty 查一下 01/07 11:19