Open othree opened 8 years ago
Asking at github/fetch https://github.com/github/fetch/issues/281
Based on the response of github/fetch#281 . We can use for...in and hasOwnProperty method to replace getOwnPropertyNames.
yep @othree, so that we can remove es5-shim and es5-sham. Do you want to propose a PR to change this?
Trying to test my modify now :smile:
Haha, solving more issues:
There are two methods to solve this. First method is use mdn.com's polyfill. Second is write simple codes to cover these new native methods. Going for second solution now.
+1, second solution looks good to me.
I have sent the PR #3 Maybe you can look into it and have some test. I just do a simple test based on the code in examples
@camsong 能否添加一个完整的代码例子,我遇到了在ie8下,始终报fetch为null的错误,以及require('es6-promise').polyfill();会报polyfill()无对象的错误~~ 谢谢
Required polyfills
// for IE8
if (!Object.getOwnPropertyNames)
{
Object.getOwnPropertyNames = function (obj: any): string[]
{
let arr = [];
for (let k in obj)
{
if (obj.hasOwnProperty(k))
arr.push(k);
}
return arr;
}
}
// for IE8
if (!Array.isArray)
{
Array.isArray = function (vArg: any | any[]): vArg is any[]
{
return Object.prototype.toString.call(vArg) === "[object Array]";
};
}
// for IE8
if (!Array.prototype.indexOf)
Array.prototype.indexOf = (function (Object, max, min)
{
"use strict"
return function indexOf(member, fromIndex)
{
if (this === null || this === undefined)
throw TypeError("Array.prototype.indexOf called on null or undefined")
var that = Object(this), Len = that.length >>> 0, i = min(fromIndex | 0, Len)
if (i < 0) i = max(0, Len + i)
else if (i >= Len) return -1
if (member === void 0)
{ // undefined
for (; i !== Len; ++i) if (that[i] === void 0 && i in that) return i
} else if (member !== member)
{ // NaN
return -1 // Since NaN !== NaN, it will never be found. Fast-path it.
} else // all else
for (; i !== Len; ++i) if (that[i] === member) return i
return -1 // if the value was not found, then return -1
}
})(Object, Math.max, Math.min);
// for IE8
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function (callback, thisArg)
{
thisArg = thisArg || window;
for (var i = 0; i < this.length; i++)
{
callback.call(thisArg, this[i], i, this);
}
};
}
// for IE8
if (!String.prototype.trim)
{
String.prototype.trim = function ()
{
// return this.replace(/^\s+|\s+$/g, '');
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};
}
if (!String.prototype.trimStart)
{
String.prototype.trimStart = function ()
{
// return this.replace(/^\s+/g, '');
return this.replace(/^[\s\uFEFF\xA0]+/g, '');
};
}
if (!String.prototype.trimEnd)
{
String.prototype.trimEnd = function ()
{
// return this.replace(/\s+$/g, '');
return this.replace(/[\s\uFEFF\xA0]+$/g, '');
};
}
Hi
I think this requires es5-shim and es5-sham is because of getOwnPropertyNames. A simple for...in can also deal with this scenario. Not sure why the first commit at github uses this method. Do you have any idea?
Willing to give a PR