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

    function Person(name,age){

    this.name = name;

    this.age=age;

    this.alertName = function(){

    alert(this.name);

    }

    this.alertAge = function(){

    alert(this.age);

    }

    }

    function webDever(name,age,sex){

    Person.call(this,name,age);

    this.sex=sex;

    this.alertSex = function(){

    alert(this.sex);

    }

    }

    var test= new webDever("愚人码头",28,"");

    test.alertName();//愚人码头

    test.alertAge();//28

    test.alertSex();//

    这样 webDever类就继承Person类,Person.call(this,name,age) 的 意思就是使用 Person构造函数(也是函数)在this对象下执行,那么 webDever就有了Person的所有属性和方法,test对象就能够直接调用Person的方法以及属性了;

  • 相关阅读:
    poj 1634
    poj 2153
    POJ 1693
    poj 1789
    POJ 2676
    vue 路由
    用 node.js 创建第一个Hello World
    js原生Ajax 的封装和原理
    BFC原理
    怎么理解js的面向对象编程
  • 原文地址:https://www.cnblogs.com/Kazaf/p/2405741.html
Copyright © 2011-2022 走看看