Blogger Information
Blog 35
fans 0
comment 0
visits 26694
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
构造函数(原型属性:prototype)
锋芒天下的博客
Original
596 people have browsed it

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <title>构造函数</title>
</head>
<body>

<script>
   // 创建一个Obj函数
       var Obj = function () {
           // 向对象赋值,给他创建一些属性和方法;
           this.color = 'black';
           this.width = '500px';
           this.height = '300px';
           this.f = function (box) {
               var x = '方泽网络';
               return x + box;
           }
       }

   // 原型属性:prototype
       Obj.prototype.size = '24px';
       Obj.prototype.bg = 'red';
       Obj.prototype.gongneng = function () {
           return '能打电话';
       }

       var obj = new Obj()
       document.write(obj.size + '<br>');
       document.write(obj.bg + '<br>');
       document.write(obj.gongneng());


</script>

</body>
</html>

//浏览器输出效果:

屏幕快照 2019-07-11 下午1.38.45.png

Correction status:qualified

Teacher's comments:案例举的不是很贴切, 但原理你是了解的
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments