很想知道ES6中是否有任何部分可以使这种检查更加简洁:
componentWillReceiveProps(nextProps) { if(nextProps && nextProps.filterObj && nextProps.filterObj.area){ // go ahead } }
发布于 2015-05-22 12:32:16
不,没有存在主义运算符将它输入到ES6中;不过,它是仍在讨论中。
当然,您可以使用任何一个现有方法,比如
if ( ((nextProps||{}).filterObj||{}).area ) { // go ahead }
此外,您还可以尝试销毁和默认值:
function componentWillReceiveProps({filterObj: {area} = {}} = {}) { if (area) { // go ahead } }
https://stackoverflow.com/questions/30395108
相似问题