safe-touch::chains: 运行时可选链接

时间:2024-06-20 04:04:30
【文件属性】:

文件名称:safe-touch::chains: 运行时可选链接

文件大小:6KB

文件格式:ZIP

更新时间:2024-06-20 04:04:30

javascript-library typescript-library development-tools TypeScript

安全触摸 轻松安全地触摸深埋财产。 这就像运行时的​​可选链接。 它在 npm 上可作为safe-touch使用。 存在的问题 有时,我们会挖掘深埋的属性: const value = someObject . key1 . key2 . key3 如果链中间的任何值是假的,就会抛出一个错误,即Uncaught TypeError: Cannot read property of undefined 如果我们试图让它更安全,代码就会变得冗长。 const value = someObject && someObject . key1 && someObject . key1 . key2 && someObject . key1 . key2 . key3 // or try { const value = someObject . key1 . key2 . key3 }


【文件预览】:
safe-touch-master
----.gitignore(25B)
----package.json(556B)
----tsconfig.json(327B)
----README.md(2KB)
----index.ts(1KB)
----test()
--------make-properties-required.ts(486B)
--------benchmarks.ts(3KB)
--------index.ts(3KB)
----yarn.lock(348B)

网友评论