ES6 类

//class里面可以放多个函数(类的多方法声明)
class Coder{
    // val是类函数的参数(函数的传参)
    name(val){
        console.log(val);
        return val;
    }
    skill(val){
        console.log(this.name('nl:')+':'+'Skill'+val);
    }
    //类的传参
    constructor(a,b){
        this.a=a;
        this.b=b;
    }
    add(){
        return this.a+this.b;
    }
}

// let nl=new Coder;
// // nl.name('君');
// nl.skill('web');
let nl=new Coder(1,2);
console.log(nl.add());

class htmler extends Coder{

}
let jun=new htmler;
jun.name('ming');
原文地址:https://www.cnblogs.com/NeryXJ/p/9651221.html