我正在使用jQuery、Backbone(和下划线)和RequireJS。
我有这个代码:
var products = _.map(items, function(item) {
return new ProductModel({
title: item.product.title,
description: item.product.description,
link: item.product.link,
'image-src': item.product.images[0].link,
'image-height': item.product.images[0].height,
'image-width': item.product.images[0].width
});
});
不幸的是,一切都可能是null
。我的意思是item, item.product, item.product.images, item.product.images[0]
,等等可能是null
s。
我正在寻找类似“合并”的东西:
- 将知道如何处理
null
s 并且不会为item.product
ifitem
is抛出异常null
。 - 如果存在
null
.
有这样的吗?