JavaScript对象模式有何特点,怎样实现对象模式
Admin 2022-05-31 群英技术资讯 1275 次浏览
这篇文章给大家分享的是“JavaScript对象模式有何特点,怎样实现对象模式”,对大家学习和理解有一定的参考价值和帮助,有这方面学习需要的朋友,接下来就跟随小编一起学习一下吧。
1、匹配对象。如果有省略号,对象可以有更多的属性。
2、只检测自己的属性(Object.keys),忽略原型中的属性。对象语法支持特殊识别属性,快速属性,属性不支持尾逗号。
实例
test("value object", () => {
let input = '{}'
let y = match(input)
let v = y({})
let w = y({ x: 0 })
expect(v).toEqual(true)
expect(w).toEqual(false)
})
test("object ELLIPSIS", () => {
let input = '{...}'
let y = match(input)
let v = y({})
let w = y({ x: 0 })
let p = y([])
expect(v).toEqual(true)
expect(w).toEqual(true)
expect(p).toEqual(false)
})
test("object properties", () => {
let input = '{x}'
let y = match(input)
let v = y({ x: 0 })
let w = y([null, 1])
expect(v).toEqual(true)
expect(w).toEqual(false)
})
test("object properties ELLIPSIS", () => {
let input = '{x,...}'
let y = match(input)
let v = y({ x: 0, y: 1 })
let w = y({})
expect(v).toEqual(true)
expect(w).toEqual(false)
})
test("properties properties prop", () => {
let input = '{x,y}'
let y = match(input)
let v = y({ x: 0, y: 1 })
let w = y({})
expect(v).toEqual(true)
expect(w).toEqual(false)
})
test("prop key value", () => {
let input = '{x:null}'
let y = match(input)
let v = y({ x: null })
let w = y([null, 1])
expect(v).toEqual(true)
expect(w).toEqual(false)
})
test("key QUOTE", () => {
let input = '{"1":null}'
let y = match(input)
let v = y({ '1': null })
let w = y([null, 1])
expect(v).toEqual(true)
expect(w).toEqual(false)
})
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
在大多数 web 产品中,全局的 Message 组件占有较大的使用场景,本文主要介绍了Vue3实现Message消息组件示例,需要的朋友们下面随着小编来一起学习学习吧
删除方法:1、用removeClass()或toggleClass()移除指定CSS类,语法“removeClass("类名")”或“toggleClass("类名")”;2、用removeAttr()去除id、class或style属性。
代码分片是webpck打包工具所特有的一项技术,通过这项功能可以把代码按照特定的形式进行拆分,使用户不必一次全部加载,而是按需加载。本文就来详细介绍,感兴趣的可以了解一下
这篇文章主要介绍了Vue2的diff算法的相关资料,帮助大家更好的理解和使用vue框架,感兴趣的朋友可以了解下
JS中require方法怎样用?一些新手对于node.js中require方法不是很了解,对此这篇文章就主要给大家分享一下node.js中require方法以及加载规则,有着方面学习需求的朋友就接着看吧。
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008