您现在的位置是:课程教程文章
js对象模式如何理解
2023-12-13 22:48课程教程文章 人已围观
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) })
以上就是js对象模式的理解,希望对大家有所帮助。更多js学习指路:js教程
课程教程:js对象模式如何理解上一篇:c语言中fwirte函数的使用
下一篇:没有了