首页 > 其他 > 详细

prototype

时间:2014-02-21 08:43:12      阅读:381      评论:0      收藏:0      [点我收藏+]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html";charset="gbk"/ >
<script type="text/javascript" >
 /*function Cat(name){
     this.name=name;
  this.show=function(){
      alert(this.name);
  };
 }
 var c1 = new Cat("大黄");
 var c2 = new Cat("小白");
 c1.show();
 c2.show();
 alert(c1.show ==c2.show);*/

 function Cat(name){
       this.name= name;
  }
  Cat.prototype.type="猫科动物";
  Cat.prototype.show=function(){
       alert(this.name);
  }
       var c1 = new Cat("大黄");
    var c2 = new Cat("小白");
    alert(c1.show ==c2.show);
       alert(Cat.prototype.isPrototypeOf(c1));
    alert(c1.hasOwnProperty("type"));
</script>
</head>
<body>
   
</body>
</html>

 

javascript中的每个对象都有prototype属性,Javascript中对象的prototype属性的解释是:返回对象类型原型的引用。

A.prototype = new B();

理解prototype不应把它和继承混淆。A的prototype为B的一个实例,可以理解A将B中的方法和属性全部克隆了一遍。A能使用B的方法和属性。这里强调的是克隆而不是继承。可以出现这种情况:A的prototype是B的实例,同时B的prototype也是A的实例。


http://www.cnblogs.com/yjf512/archive/2011/06/03/2071914.html

prototype

原文:http://www.cnblogs.com/lowbrid/p/3558296.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!