feipeng
V2EX  ›  jQuery

jQuery.extend 在深复制时,为什么需要判断 isPlainOjbect?(不是问 isPlainOjbect 方法的原理)

  •  
  •   feipeng · Apr 1, 2019 · 5144 views
    This topic created in 2611 days ago, the information mentioned may be changed or developed.
    3 replies    2019-04-01 22:22:00 +08:00
    mywaiting
        1
    mywaiting  
       Apr 1, 2019
    防止递归的死循环?我猜的~
    feipeng
        2
    feipeng  
    OP
       Apr 1, 2019
    自己想通了==
    ```
    function Person(){
    this.name = "张三";
    }
    let person = new Person();
    person.age = 12;
    ```
    上面的 person 就是一个非 plain object,person 的__proto__为 Person,在使用 for in 遍历复制之后的对象的__proto__却变成了 Object,显然复制前后不对等,故要使用 isPlainObject 方法进行过滤
    feipeng
        3
    feipeng  
    OP
       Apr 1, 2019
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1348 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 17:03 · PVG 01:03 · LAX 10:03 · JFK 13:03
    ♥ Do have faith in what you're doing.