![图片[1]-js对象模式如何理解-uusu优素-乐高,模型,3d打印,编程](https://uusu.cn/wp-content/uploads/2025/01/1635215379116840.png)
1、匹配对象。如果有省略号,对象可以有更多的属性。
2、只检测自己的属性(Object.keys),忽略原型中的属性。对象语法支持特殊识别属性,快速属性,属性不支持尾逗号。
实例
test("valueobject",()=>{
letinput='{}'
lety=match(input)
letv=y({})
letw=y({x:0})
expect(v).toEqual(true)
expect(w).toEqual(false)
})
test("objectELLIPSIS",()=>{
letinput='{...}'
lety=match(input)
letv=y({})
letw=y({x:0})
letp=y([])
expect(v).toEqual(true)
expect(w).toEqual(true)
expect(p).toEqual(false)
})
test("objectproperties",()=>{
letinput='{x}'
lety=match(input)
letv=y({x:0})
letw=y([null,1])
expect(v).toEqual(true)
expect(w).toEqual(false)
})
test("objectpropertiesELLIPSIS",()=>{
letinput='{x,...}'
lety=match(input)
letv=y({x:0,y:1})
letw=y({})
expect(v).toEqual(true)
expect(w).toEqual(false)
})
test("propertiespropertiesprop",()=>{
letinput='{x,y}'
lety=match(input)
letv=y({x:0,y:1})
letw=y({})
expect(v).toEqual(true)
expect(w).toEqual(false)
})
test("propkeyvalue",()=>{
letinput='{x:null}'
lety=match(input)
letv=y({x:null})
letw=y([null,1])
expect(v).toEqual(true)
expect(w).toEqual(false)
})
test("keyQUOTE",()=>{
letinput='{"1":null}'
lety=match(input)
letv=y({'1':null})
letw=y([null,1])
expect(v).toEqual(true)
expect(w).toEqual(false)
})原文来自:https://www.py.cn © 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END




















































暂无评论内容