假设我有一个javascript模块first_file.js
var first = "first",
second = "second",
third = "third";
module.exports = {first, second, third};
如何在一行中将这些导入到另一个文件中?以下代码仅导入third
var first, second, third = require('./path/to/first_file.js');
我有一个对象,它有两个函数:foo和bar。bar调用foo。通常,当bar使用this.foo()时,这可以很好地工作。但是,在解构对象时,this不再引用该对象。在下面的代码片段中,它是未定义的。当我在chrome中运行它时,它引用了window对象。
预期输出
func1()
foo
objectValue
foo
bar
func2()
foo
objectValue
foo
bar
实际产出
func1()
foo
objectValue
foo
bar
func2()
foo
globalValue (or Uncaught TypeError, in the case of
我遇到了一个出口场景的小问题,我不知道为什么。我可能需要一个Babel插件来解决它,但不确定是哪个。
// a.js
export function fromA() {}
// b.js
export function fromB() {}
// index.js
import * as a from './a'
import * as b from './b'
export default { ...a, ...b}
// test.js
import all from './index'
const { fromA } = all