es5和es6声明类的区别/es5和es6继承的区别

// es5和es6声明类的区别,es5没有统一语法规范。es6有统一写法规范 start。
// es5声明“类”的语法--伪类
// function Person(name,age){
//     this.name = name;
//     this.age = age;
//     // this.showName = function(){
//     //     alert(this.name);
//     // };
//     // this.showAge = function(){
//     //     alert(this.age);
//     // }
// }
// Person.prototype.showName = function(){
//     alert(this.name)
// }
// Person.prototype.showAge = function(){
//     alert(this.age)
// }
// let p = new Person('blue',18);
// p.showName();
// p.showAge();

// es6有单独的声明类的方法
// class Person{
//     constructor(name,age){
//         this.name = name;
//         this.age = age;
//     }
//     showName(){
//         alert(this.name);
//     }
//     showAge(){
//         alert(this.age);
//     }
// }
// let p = new Person('red',19)
// p.showName();
// p.showAge();
// es5和es6声明类的区别,es5没有统一语法规范。es6有统一写法规范 end。
// es5和es6的继承区别 ----------------- start
// es5
// function Person(name,age){
//     this.name = name;
//     this.age = age;
// }
// Person.prototype.showName = function(){
//     alert(this.name)
// }
// Person.prototype.showAge = function(){
//     alert(this.age)
// }
// function Worker(name,age,job){
//     Person.call(this,name,age);
//     this.job = job;
// }
// Worker.prototype = new Person()
// Worker.prototype.constructor = Worker;
// Worker.prototype.showJob = function(){
//     alert(this.job);
// };
// let w = new Worker('huihui',2,'大学教授');
// w.showName();
// w.showAge();
// w.showJob();

// es6
class Person{
    constructor(name,age){
        this.name = name;
        this.age = age;
    }
    showName(){
        alert(this.name);
    }
    showAge(){
        alert(this.age);
    }
}
class Worker extends Person{
    constructor(name,age,job){
        super(name,age);
        this.job = job;
    }
    showJob(){
        alert(this.job);
    }
}
let w = new Worker('张景辉','28','大学教授');
w.showName();
w.showAge();
w.showJob();
// 
// es5和es6的继承区别 ----------------- end

 如果对小哥哥小姐姐有帮助请点个推荐哈,欢迎留言、评论、搞事!!   双肩背包 【正品折扣专业店】 -- biy1314.taobao.com

转载于:https://www.cnblogs.com/jwzhang/p/11148521.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值