CNode

运算符优先级

分享
Mmagicdawn发布于10 年前最后回复10 年前0 回复4044 浏览0 收藏

运算符优先级

. = new, 但 . 是左结合

// error Date.toLocaleString is not a function
new Date.toLocaleString()

// ok
new Date().toLocaleString()

new > 函数调用

const List = require('listr'); // ES6 class

// error, 提示 class invoke without new
// 发生了什么
// new 优先级比函数调用优先级高
// 相当于 require('listr')()
// fix: 给require函数调用加一个括号, 提升优先级即 new (require('listr'))();
const list = new require('listr')();

还有什么技巧是可以用优先级解释的呢?可以分享下

查看回复

回复 (0)

暂无回复,成为第一个参与讨论的人。
参与回复
登录后即可参与回复。登录