js comma operator All In One
js comma operator All In One
The comma operator (,) evaluates each of its operands (from left to right) and returns the value of the last operand.
This lets you create a compound expression in which multiple expressions are evaluated, with the compound expression's final value being the value of the rightmost of its member expressions.
This is commonly used to provide multiple parameters to a for loop.
js 逗号运算符
(,) 计算其每个操作数(从左到右
)并返回最后一个操作数
的值
。
这使您可以创建一个复合表达式,在其中计算多个表达式,复合表达式
的最终值是其最右边的成员表达式
的值
。
这通常用于为 for 循环
提供多个参数。
let x = 1;
x = (2, 3, 7);
console.log(x);
// 7
typeof (0, console.log)(`abc`)
// abc
// 'undefined'
typeof (0, console.log)
// 'function'
log = (0, 1, 2, 3, console.log);
// ƒ log() { [native code] }
log(`test`);
// test
// undefined
log = (0, console.log);
// ƒ log() { [native code] }
log(`test`);
// test
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator
demo
(0, console.log)("hello world!")
// hello world!
function test(a, b) {
console.log(`a =`, a);
console.log(`b =`, b);
}
(test)(111, 222)
// a = 111
// b = 222
(0, test)(111, 222)
// a = 111
// b = 222
(1, test)(111, 222)
// a = 111
// b = 222
https://stackoverflow.com/questions/32275135/why-does-babel-rewrite-imported-function-call-to-0-fn
refs
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/15948281.html
未经授权禁止转载,违者必究!