js call与apply

来源:互联网 发布:电源监控软件 编辑:程序博客网 时间:2024/05/29 16:20

这里写图片描述

// 类的继承function Person(name,age){    this.name = name;    this.age = age;    this.alertName = function(){        console.log(this.name);    }    this.alertAge = function(){        console.log(this.age);    }}function webDever(name,age,sex){    Person.call(this,name,age); //Person.apply(this,arguments);    this.sex = sex;    this.alertSex = function(){        console.log(this.sex);    }}var webtest = new webDever("Jon",20,"male");webtest.alertAge(); //20
0 0