javascript 对象的三个属性 二十六

每一个对象都有与之相关的 prototype ,class 、extensible attribute 。


prototype

参考链接:https://msdn.microsoft.com/zh-cn/library/kb6te8d3(v=vs.94).aspx

isPrototypeOf 方法 (Object) (JavaScript)

确定一个对象是否存在于另一个对象的原型链中。

如果 object 的原型链中具有 prototype,则 isPrototypeOf 方法返回 true原型链用于在同一个对象类型的不同实例之间共享功能。当 object 不是对象或当 prototype 没有出现在 object 的原型链中时,isPrototypeOf 方法返回 false

<!DOCTYPE html>
<lang ="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>


      <script  type="text/javascript">

          function Pasta(grain, width) {
              this.grain = grain;
              this.width = width;
          }
          // Create an object from the pasta constructor.
          var spaghetti = new Pasta("wheat", 0.2);

          // Obtain the prototype from the object.
          var proto = Object.getPrototypeOf(spaghetti);

          // Add a property to the prototype and validate that
          // the original object has the property.
          proto.foodgroup = "carbohydrates";
          document.write(spaghetti.foodgroup + " ");

          // Verify that the prototype obtained from the object
          // is the same as the prototype of the constructor.
          var result = (proto === Pasta.prototype);
          document.write(result + " ");

          // Verify that prototype obtained from the object
          // is a prototype of the original object.
          var result = proto.isPrototypeOf(spaghetti);
          document.write(result);

        </script>

       <script type="text/javascript">
           var p = {x:1};
           var o = Object.create(p);
           p.isPrototypeOf(o)
           Object.prototype.isPrototypeOf(o) //p 继承自 Object prototype
           </script>

</head>
<body>

</body>
</html>

类属性:




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值