js对象模式如何理解
928
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) )
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。