I found there are some expressions in some libs like this:
exports.default = (0, _createHelper2.default)(pure, 'pure', 1)
Seems like it has no difference with _createHelper2.default(pure, 'pure', 1)
So what is the purpose of writing like this?
I found there are some expressions in some libs like this:
exports.default = (0, _createHelper2.default)(pure, 'pure', 1)
Seems like it has no difference with _createHelper2.default(pure, 'pure', 1)
So what is the purpose of writing like this?
There's a small difference: The value of this used when calling _createHelper2.default:
With
exports.default = (0, _createHelper2.default)(pure, 'pure', 1)
_createHelper2.default will be called with this set to either the global object (loose mode) or undefined (strict mode).
With
_createHelper2.default(pure, 'pure', 1)
_createHelper2.default will be called with this set to _createHelper2.
(Whether _createHelper2.default actually sees the this value used for the call depends on uses on whether it's a normal function, a bound function, or an arrow function; but that's the difference in the call to it.)
exports.default = (0, _createHelper2.default)(pure, 'pure', 1) works by using the comma operator to get the function reference without associated property information, and then calls that function not via a property access, which bypasses the usual setting of this. So it's like doing this:
var f = _createHelper2.default;
exports.default = f(pure, 'pure', 1)