js 原型链

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <script type="text/javascript">

  var person = function (name) {
    this.name = name;
  };
  person.prototype.getName = function() {
    return this.name;
  };

  var student = new person('jerome');

  console.log(student); // person { name: 'jerome' }
  console.log(student.prototype); //undefined, 对象原型没有prototype
  console.log(student.__proto__); // person {}

  console.log(person); // function person(name)
  console.log(person.prototype); // person {}
  console.log(person.__proto__); // function Empty()
  console.log(person.prototype.prototype); // undefined
  console.log(person.prototype.__proto__); // Object {}

  console.log(Object.prototype); // Object {}
  console.log(Object.__proto__); // function Empty()

  console.log(Function.prototype); // function Empty()
  console.log(Function.__proto__); // function Empty()

  console.log(Object.prototype.prototype); // undefined
  console.log(Object.prototype.__proto__); // null

  console.log(Function.prototype.prototype); //undefined
  console.log(Function.prototype.__proto__); // Object {}

  // 结论:
  // student.__proto__ = person.prototype
  // person.prototype.__proto__ = Object.prototype
  // Object.prototype.__proto__ = null
  </script>
</body>
</html>

  

posted @ 2015-08-13 17:16  Jerome's Blog  阅读(179)  评论(0编辑  收藏  举报