1.constructor 属性返回对象的构造函数

  1. <script>
  2. /*面试题:如何判断一个数组是不是数组 1.Array.isArray() 2.instanceof 3.constructor
  3. 1.对象,类,原型,原型链
  4. */
  5. /*构造属性
  6. 创造构造函数时,原型对象上会有一个constructor属性,它是原型对象所独有的
  7. */
  8. function Person(name,age){
  9. this.name=name;
  10. this.age=age;
  11. }
  12. var p=new Person("cheng",20)
  13. console.log(p.constructor==Person); //true
  14. var arr=[1,2,3];
  15. console.log(arr.constructor==Array); //true
  16. </script>