azl397985856 / fe-interview

宇宙最强的前端面试指南 (https://lucifer.ren/fe-interview)
Apache License 2.0
2.83k stars 260 forks source link

【每日一题】- 2020-04-17 - ES 关键字 #114

Closed azl397985856 closed 4 years ago

azl397985856 commented 4 years ago

假如你的代码使用了ES关键字。 比如

var const = 'something';

这在ES6以前的Runtime 运行是没有问题的。 但是在支持ES6+的Runtime 就会报错。 如果项目有很多这样的东西么,那么如何解决这个问题呢?

扩展:

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

azl397985856 commented 4 years ago

写一个babel 插件转化一下,思路:

关于如何找到作用域中不存在,实际上 eslint 有专门的 api 可以用。 如果你自己写的话, 基本上就是扫描所有的变量声明然后把每一个变量声明记录到一个哈希表中即可。

特别需要注意的是:

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.