91-babel转义import

fu()和(0,fu)()有什么区别

1
2
3
4
5
import { a } from 'b';

function x () {
a()
}

babel转成以下代码:

1
2
3
4
5
6
7
'use strict';

var _b = require('b');

function x() {
(0, _b.a)();
}

(0, _b.a)() ensures that the function _b.a is called with this set to the global object (or if strict mode is enabled, to undefined).

(0, _b.a)()确保 function _b.a this 绑定到当前全局变量,如果是在严格模式,则绑定到undefined。 如果你直接使用_b.a,则this指向的是_b