微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐