babel-polyfill 是如何实现在 IE 把 Array.from polyfill 为 native code 的?

2020-03-22 00:12:23 +08:00
 serge001

使用 vue-cli3 的脚手架,默认配置了 polyfill 了.我在 index.html 中手动重置 Array.prototype.includes 为 undefined, 然后在组件中使用 Array.includes 方法,然后在控制台中打印 Array.prototype.includes,打印出来的结果均为 fuction () {native code}

这让我觉得有点不可思议,对于 chrome 来说,因为 includes 方法本身就是 native support 的,我重置后,babel 还可以通过 iframe 来恢复,可是对于 ie 来说,本来就没有对 includes 方法支持,按道理打印出来的应该是 polyfill 的代码而不是 native code,babel 怎么实现这种黑魔法的?

2385 次点击
所在节点    JavaScript
4 条回复
serge001
2020-03-22 00:29:11 +08:00
可以打开这个链接在 IE 中测试 https://gaoshijun1993.github.io/
randyo
2020-03-22 00:33:20 +08:00
应该不是吧,打断点都能进去
Kokororin
2020-03-22 00:38:03 +08:00
autoxbc
2020-03-22 03:18:52 +08:00
const fn = () => 42 ;
fn.toString = () => 'function() { [native code] }';

console.log(fn);

>>'function() { [native code] }'

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/654985

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX