zoukankan      html  css  js  c++  java
  • js call

    要求:
    在Autobots构造函数中使用call借用Car构造函数实现name属性的继承
    在Car构造函数的原型中添加一个run方法,并通过原型继承给Autobots构造函数的实例对象
    希望Autobots构造函数创建的实例对象能够拥有变形(distort方法)的能力

        注意:普通汽车不能变形,汽车人是可以变形的。
        汽车人对象将会有name,color属性,而且拥有run,distort方法
        其中name,distort都是通过继承得来的。
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <script>
          
         //创建car构造函数
         function Car(name){
             this.name=name;
             //原型中添加方法不确定这样对不对
             this.distort=function(){
             console.log("我还会变形");
          }
         }
    
    
     
         //创建Autobots构造函数
         function Autobots(color){
             this.color=color;
            //继承car,同时还传递参数
            Car.call(this,"我是大黄蜂");
            //添加变形方法
            this.run=function(){
                console.log("不仅会飞,还会跑");
            }
         }
          
        //实例化传入color
         var Deformation = new Autobots("黄色");
         //通过原型继承run方法
         Autobots.prototype.distort;
         //打印
         console.log(Deformation.name+Deformation.color);
         Deformation.run()
         Deformation.distort();
        </script>
    </head>
    <body>
        
    </body>
    </html>
    

  • 相关阅读:
    排序算法之冒泡排序
    排序算法之快速排序
    排序算法之插入排序
    Java集合之LinkedList源码分析
    排序算法之选择排序
    Java集合之Vector源码分析
    Python 装饰器
    一致性哈希
    剑指Offer-数组中重复的数字
    剑指Offer-把字符串转换成整数
  • 原文地址:https://www.cnblogs.com/shapaozi/p/10544685.html
Copyright © 2011-2022 走看看