for ... in

    "use strict";
        
        const t = {
            height: 111
        }
        
      function CreateP(name, age) {
            this.name = name;
            this.age = age;
        }
        CreateP.prototype = t;
        
        const p = new CreateP('sky', 23);
    
    
    
     for (let k in p) {
          console.log(k); // name, age, height

   // 除了遍历自身可枚举的属性外,还会遍历原型中可枚举的属性
     }

posted @ 2021-07-07 09:17  sky-su  阅读(45)  评论(0)    收藏  举报