zoukankan      html  css  js  c++  java
  • js里的继承

    1、new做的事情a、创建一个Object对象【O】。b、将new后面的function对象的【自身属性】和【prototype的属性】

        赋值给【O】

    2、js中的访问“对象的属性”例如a.b是有先后顺序的,即先访问【自身的属性】,然后访问【prototype的属性】。

    <script>
    persion=function()
    {
     this.print=function()
     {
       alert('print persion');
     }
    }
    persion.prototype.ask=function()
    {
     alert('persion ask');
    }


    child=function()
    {
     persion.call(this);//将persion的【自身属性】作为child的【自身属性】
    }

    //把persion的【自身属性】和【prototype的属性】都作为child的【prototype的属性】
    child.prototype=new persion();
    child.prototype.constructor=child;//修改child的constructor

    child.prototype.print=function()
    {
     alert('child print');
    }

    var c=new child();
    c.print();
    c.ask();
    </script>

  • 相关阅读:
    事件记录
    C++和extern C
    中断控制器
    NAND FLASH控制器
    MMU实验
    存储管理器实验
    GPIO实验
    linux与Windows使用编译区别及makefile文件编写
    ubuntu如何为获得root权限
    VI常用命令及linux下软件
  • 原文地址:https://www.cnblogs.com/kuailewangzi1212/p/1372669.html
Copyright © 2011-2022 走看看