码迷,mamicode.com
首页 > Web开发 > 详细

js 原型链

时间:2015-08-13 19:33:10      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

<!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>

  

js 原型链

标签:

原文地址:http://www.cnblogs.com/linji/p/4727894.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!