V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
feipeng
V2EX  ›  jQuery

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

  •  
  •   feipeng · Apr 1, 2019 · 5084 views
    This topic created in 2590 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   ·   2704 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 03:29 · PVG 11:29 · LAX 20:29 · JFK 23:29
    ♥ Do have faith in what you're doing.