[Javascript Crocks] Safely Access Nested Object Properties with `propPath`
In this lesson, we’ll look at the propPath
utility function. We’ll ask for a property multiple levels deep in an object and get back a Maybe. We’ll get a Just
when the property exists at our path and a Nothing
if any part of the path is undefined
.
const propPath = require('crocks/Maybe/propPath') const user = {
username: 'tester',
email: 'test@gmail.com',
address: {
street: '111 E. West St',
city: 'Anywhere',
state: 'PA',
postalCode: '19123-4567'
}
}; const getPostalCode = propPath(['address', 'postalCode']);
const zip = getPostalCode(user).option('not available'); console.log(zip) //'19123-4567'
[Javascript Crocks] Safely Access Nested Object Properties with `propPath`的更多相关文章
- [Javascript Crocks] Safely Access Object Properties with `prop`
In this lesson, we’ll use a Maybe to safely operate on properties of an object that could be undefin ...
- Initializing nested object properties z
public class Employee { public Employee() { this.Insurance = new Insurance(); } // Perhaps another c ...
- [Javascript Crocks] Flatten Nested Maybes with `chain`
Sometimes, we run into situations where we end up with a Maybe within the context of another Maybe. ...
- javascript nested object merge
javascript nested object merge deep copy Object reference type function namespace(oNamespace, sPacka ...
- [Functional Programming] Using Lens to update nested object
For example, in React application, we have initial state; const data = { nextId: 4, todoFilter: 'SHO ...
- 67.基于nested object实现博客与评论嵌套关系
1.做一个实验,引出来为什么需要nested object 冗余数据方式的来建模,其实用的就是object类型,我们这里又要引入一种新的object类型,nested object类型 博客,评论,做 ...
- Vue开发警告[Vue warn]: Avoid replacing instance root $data. Use nested data properties instead.
Avoid replacing instance root $data. Use nested data properties instead. 翻译 避免替换实例根$data.请改用嵌套数据属性 错 ...
- JavaScript中你所不知道的Object(二)--Function篇
上一篇(JavaScript中你所不知道的Object(一))说到,Object对象有大量的内部属性,而其中多数和外部属性的操作有关.最后留了个悬念,就是Boolean.Date.Number.Str ...
- 【Selenium】【BugList8】126邮箱定位不到“退出”按钮:Message: TypeError: can't access dead object
[流程描述] 登录126邮箱,退出 [代码] #coding=utf-8 from selenium import webdriver driver = webdriver.Firefox() #dr ...
随机推荐
- PCB MS SQL 小写转大写
由于SQL Server允许为小写进入 ,导致数据库中存在小写,在数据集成到MES或ERP时报错,Oracle要求大写导致, 需转换为大写,可通过以下语句,查询所有小写数据,再更新.
- php多个进程写文件
多进程写文件function write_file($filename, $content){ $lock = $filename . '.lck'; $write_length = 0; while ...
- DIV+CSS设计时浏览器兼容性
近期用Div+css做了个企业网站,在浏览器中测试的时候确发现在IE7中显示正常的页面,在ie6中非常混乱,当时第一感觉就想到了兼容问题,可是百思不得其解应该从哪下手,经过一两天的查资料, ...
- Oracle 批量插入值
工作中常遇到将Excel文档数据转为SQL语句,然后再将SQL语句插入到数据库已完成数据转移保存到数据库中,下面介绍下如何一次性插入多条SQL语句,先抛个图: 由于真实数据不变给大家看,所以这里是做了 ...
- gdb打印vector
1.gdb版本大于7.0 (gdb) p yourVector 2.打印整个vector (gdb) p *(yourVector._M_impl._M_start)@yourVector.size( ...
- js仿新浪游戏频道导航条
js仿新浪游戏频道导航条 在线演示本地下载
- 远程连接Oracle设置
1:打开net manager:开始->程序->oracle->配置和移植工具->Net Manager 2:添加服务器名->名子自定义,一般根据项目自定义,自己知道就行 ...
- OAuth四种模式
授权码模式(authorization code)----适用于网站服务端去oauth服务端申请授权 简化模式(implicit)----没有服务端,js+html页面去oauth服务端申请授权 密码 ...
- 理解Python中编码的应用
完全理解字符编码 与 Python 的渊源前,我们有必要把一些基础概念弄清楚,虽然有些概念我们每天都在接触甚至在使用它,但并不一定真正理解它.比如:字节.字符.字符集.字符码.字符编码. 字节 字节( ...
- web开发——在网页中引用字体包(.ttf),即嵌入特殊字体
在写html时,有点时候需要显示一些特殊字体,不过这些特殊字体是系统一般不自带的,这时就需要我们自行加载要用的字体.方法如下: 1.首先在style里添加: @font-face { font-fam ...