1. Object.create
2. Object.freeze()
用法:
Object.freeze(a) //使得object a 里面的属性值readonly, 不可改变
但是a也仅仅是浅冻住、
如果 a = {b:{c:2}}, Object.freeze(a)
然后 a.b.c = 5;
最终a.b.c 变成了5
3. react pureComponent
export default function PureComponent(props, context) {
Component.call(this, props, context)
}
PureComponent.prototype = Object.create(Component.prototype)
PureComponent.prototype.constructor = PureComponent //原型链继承
PureComponent.prototype.shouldComponentUpdate = shallowCompare
function shallowCompare(nexProps, nextState) {
return !shallowEqual(this.props, nextProps) || !shollowEqual(this.state, nextState)
}
//shallowEqual
export default function shallEqual(objA, objB) { // 从后面代码可以看出,对于两个对象的比较为这里的代码 if (objA === objB) { return true; } if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { return false; } const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA.length !== keysB.length) { return false; } // Test for A's keys different from B. for (let i = 0; i < keysA.length; i++) { if (!objB.hasOwnProperty(keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) { return false; } } return true; }
4. object.keys是非原型链的属性值。同hasOwnProperty
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS.hasOwnProperty(propName)
5. Array(4)
返回长度为4的空数组
6. react的基础
element.$$typeof = REACT_ELEMENT_TYPE
const symbolFor = Symbol.for;
REACT_ELEMENT_TYPE = symbolFor('react.element');