记录一些有用的代码片段
javascript
- 比较一个大的对象中的除了某一个子对象的其他对象是否相等 12345678componentWillReceiveProps (nextProps) {const staticNextProps = lodash.cloneDeep(nextProps)delete staticNextProps.columnsconst { columns, ...otherProps } = this.propsconst isEqual = lodash.isEqual(staticNextProps, otherProps));......}
点评
很巧妙的在不破坏原数据(nextProps)的情况下深拷贝出来一个对象staticNextProps,因为不需要比较columns这个子对象,然后删除这个子对象,最后更巧妙地是使用ES6的rest运算符…otherProps将this.props中除了cloumns子对象的其他对象包装成一个新的对象,最后使用lodash的isEqual深比较方法进行比较,非常犀利的思路!
此段代码来自antd-admin示例代码