怎么实现链式调用

var user = function(name, age) {
      this.name = name;
      this.age = age;
    };
    user.prototype.getName = function() {
      console.log(this.name);
      return this;
    };
    user.prototype.getAge = function() {
      console.log(this.age);
      return this;
    };
    var user1 = new user("zjf", 22);
    user1.getName().getAge()

 只需要在方法后直接return出this即可

posted @ 2020-06-14 18:24  文学少女  阅读(311)  评论(0编辑  收藏  举报