这个 javascript 语法是什么意思?(0, _parseKey2.default)(东西) [英] What does this javascript syntax mean ? (0, _parseKey2.default)(something)

查看:14
本文介绍了这个 javascript 语法是什么意思?(0, _parseKey2.default)(东西)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Webpack 生成的库中到处都发现这个符号,但我不明白:

I find this notation everywhere in Webpack generated libs but I don't understand it :

var a = (0, _parseKey2.default)(something)

(0, _parseKey2.default) 代表什么?我不记得在函数参数中其他地方的括号之间看到那些逗号分隔的表达式,所以也许我只是遗漏了一些简单的东西.

What does the (0, _parseKey2.default) stands for ? I don't remember seeing those coma separated expressions between parenthesis elsewhere that in function parameters, so maybe I am just missing something simple.

感谢您的帮助.

推荐答案

这是为了给 _parseKey2.default 正确的 this (或者,更确切地说,没有 this),也就是把它作为一个普通的函数来调用,而不是一个方法.考虑:

This is to give _parseKey2.default the correct this (or, rather, no this at all), that is, to call it as an ordinary function, not a method. Consider:

var p = {
    f : function() {
        console.log(this)
    },
    x : "foo"
};

p.f();      // { f: ... x: foo }
(p.f)();    // { f: ... x: foo }
(0, p.f)(); // implicit global this

逗号表达式是一种更简洁的方法:

The comma expression is a more concise way to do this:

 var unbound = p.f;
 unbound();

这篇关于这个 javascript 语法是什么意思?(0, _parseKey2.default)(东西)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆