美文网首页
JS继承与Promise小计

JS继承与Promise小计

作者: 光影墨辰 | 来源:发表于2017-08-29 13:25 被阅读0次

    //ES6实现继承

    classPerson {

    constructor(name, age) {

    this.name= name;

    this.age= age;

    }

    Show() {

    return(this.name+' '+this.age);

    }

    }

    classStudentextendsPerson {

    constructor(name, age, School) {

    super(name, age);

    this.School= School;

    }

    Show() {

    return(super.Show() +' '+this.School);

    }

    }

    letme=newStudent("mochen","10","XD");

    //ES5继承

    functionjicheng(parent) {

    functionF(){};

    F.prototype= parent;

    return newF();

    }

    //Promise实例

    functionf(par) {

    return newPromise((resolve, reject) => {

    //异步操作

    if(true)//如果判断条件为true,即异步执行成功

    {

    resolve(参数);

    }else{

    reject(参数);

    }

    })

    }

    letmyPromise=newf(par);

    myPromise(par)

    .then(()=> {})//此处为异步成功时你要执行的函数

    .catch(() => {})//此处为异步失败你要执行的函数

    相关文章

      网友评论

          本文标题:JS继承与Promise小计

          本文链接:https://www.haomeiwen.com/subject/kjyodxtx.html