注:本文为 《 JavaScript 完全手册(2018版) 》第10节,你可以查看该手册的完整目录。
表达式是可以计算并解析为值的代码单元。JS中的表达式可以分为几类。
算术表达式
在此类别下,将所有评估为数字的表达式:
1 / 2 i++ i -= 2 i * 2
字符串表达式
评估为字符串的表达式:
'A ' + 'string' 'A ' += 'string'
基本表达
在这个类别下去变量引用,字面量和常量:
2 0.02 'something' true false this //the current object undefined i //where i is a variable or a constant
还有一些语言关键词:
function class function* //the generator function yield //the generator pauser/resumer yield* //delegate to another generator or iterator async function* //async function expression await //async function pause/resume/wait for completion /pattern/i //regex () // grouping
数组和对象初始化表达式
[] //array literal {} //object literal [1,2,3] {a: 1, b: 2} {a: {b: 1}}
逻辑表达式
逻辑表达式使用逻辑运算符并解析为布尔值:
a && b a || b !a
左边的表达式
new //create an instance of a constructor super //calls the parent constructor ...obj //expression using the spread operator
属性访问表达式
object.property //reference a property (or method) of an object object[property] object['property']
对象创建表达式
new object() new a(1) new MyRectangle('name', 2, {a: 4})
函数定义表达式
function() {} function(a, b) { return a * b } (a, b) => a * b a => a * 2 () => { return 2 }
调用表达式
调用函数或方法的语法
a.x(2) window.resize()
最新评论
写的挺好的
有没有兴趣翻译 impatient js? https://exploringjs.com/impatient-js/index.html
Flexbox playground is so great!
感谢总结。
awesome!
这个好像很早就看到类似的文章了
比其他的教程好太多了
柯理化讲的好模糊…没懂