zoukankan      html  css  js  c++  java
  • javascript实现继承的方法

    1:JS原型(prototype)实现继承

    function Person(){}
       person.prototype.hello="hello";
       person.prototype.sayHello=function(){
          alert(this.hello);
    }
    
    function Child(){}
      child.prototype=new Person();
      child.prototypr.word="keeny";
      child.prototype.sayWord=(){
         alert(this.word);
    }
     
     var c=new Child();
          c.sayHello;
          c.sayWord;

    2:call()方法实现继承

         call的参数:第一个参数this值,第二个参数:参数直接传递给函数

          

    function sun(){
    
    }

    3:apply()方法实现继承

       apply的参数:第一个参数是在其中运行函数的作用域,第二个参数是参数数组(可以是Array的实例,也可以是arguments对象),

    4:对象冒充实现继承

    5:

  • 相关阅读:
    将图片转换为base64 格式
    BFC
    面试
    不足之处
    html 调用摄像头 并抓拍
    css,js零散知识的整理
    语义化标签SEO
    Modernizr
    快速排序(2)
    快速排序(1)
  • 原文地址:https://www.cnblogs.com/lulu-front/p/4946403.html
Copyright © 2011-2022 走看看