zoukankan      html  css  js  c++  java
  • js基础

    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');
  • 相关阅读:
    9、Spring Boot 2.x 集成 Thymeleaf
    【专题】Spring Boot 2.x 面试题
    8、Spring Boot 2.x 服务器部署
    7、Spring Boot 2.x 集成 Redis
    6、Spring Boot 2.x 集成 MyBatis
    5、Spring Boot 2.x 启动原理解析
    4、Spring Boot 2.x 自动配置原理
    3、Spring Boot 2.x 核心技术
    2、Spring Boot 2.x 快速入门
    centOS下安装JDK1.8.60,glassfish4.1.1以及MySQL
  • 原文地址:https://www.cnblogs.com/connie313/p/14856097.html
Copyright © 2011-2022 走看看