Sunny-117 / js-challenges

✨✨✨ Challenge your JavaScript programming limits step by step

Home Page:https://juejin.cn/column/7244788137410560055

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

链式调用

Sunny-117 opened this issue · comments

链式调用
const count = {
    value:0,
    add:function(newValue){
        this.value += newValue;
        return this;
    },
    del:function(newValue){
        this.value -= newValue;
        return this;
    }
}
let obj = {
  value: 1,
  increment: function () {
    this.value += 1;
    return this;
  },
  add: function (v) {
    this.value += v;
    return this;
  },
  shout: function () {
    console.log(this.value);
    return this;
  }
};

obj.increment().add(3).shout(); // 输出:5