作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
import {
foobar1,
foobar2,
foobor3, //typo! this key doesn't exist in the module.
} from './module_file.js'
console.log(foobar1, foobar2, foobar3) //EXPLODES
我在使用新的 ES6 样式导入语句时犯的最常见的愚蠢错误之一是我在对象解构中的一个键中有错字。我想不出有哪个实例是我希望解构赋值中的值是 undefined
的。如果我尝试导入的其中一项未定义,是否有任何方法可以强制导入语句快速失败?
即:
import {
doesntExistInModule //EXPLODE NOW! 🔥🔥🔥
} from './module_file.js'
最佳答案
- There is no hook allowing a module to run some code before its dependencies load. This means that modules have no control over how
their dependencies are loaded.- There is no error recovery for import errors. An app may have hundreds of modules in it, and if anything fails to load or link, nothing runs. You can’t import in a try/catch block. (The upside here is that because the system is so static, webpack can detect those errors for you at compile time.)
更多详情,read it out
关于javascript - 使用 ES6 import 语句时,有没有办法防止未定义的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36805664/
我是一名优秀的程序员,十分优秀!