2017-06-07 心情不美丽。 以下为本地读书记录。

 Object.keys()方法可返回对象所有枚举属性,如:

  function Person() {}

  Person.prototype.name = 'Tom';

  Person.prototype.age = 24;

  Person.prototype.sayName = function() {alert(this.name);};

  console.log(Object.keys(Person.prototype)); // 输出name,age, sayName三个属性

  var person = new Person;

  person.name = 'Json';

  person.age = 25;

  console.log(Object.keys(person)); // 输出Person实例对象的属性, name,age

   Object.getOwnPropertyNames()可返回对象所有属性,包括非枚举类型属性,如:

  console.log(Object.getOwnPropertyNames(Person.prototype)); // 输出所有属性,constructor, name, age, sayName. 其中constructor构造器为非枚举类型。

原型的动态性