为了账号安全,请及时绑定邮箱和手机立即绑定

在js中关于return this的问题

在js中关于return this的问题

慕娘9325324 2018-08-06 06:05:21
on: function(event, fn) {    var handles = this._handles || (this._handles = {}),      calls = handles[event] || (handles[event] = []);    // 找到对应名字的栈    calls.push(fn);    return this;  }在这个函数中,return this到底是什么意思,调用这个函数的时候并没有和赋值语句一起使用啊?请问为何还要使用?
查看完整描述

1 回答

?
天涯尽头无女友

TA贡献1831条经验 获得超9个赞

如果你知道jq的链式写法, 就知道为什么要return this了...

var a = {    b: function(bb) {        console.log(bb)        return this;
    },    c: function(cc) {        console.log(cc)        return this;
    },    d: function(dd) {        console.log(dd)        return this;
    }
}
a.b(1).c(2).d(3);// 1// 2// 3// Object {}


查看完整回答
反对 回复 2018-09-14
  • 1 回答
  • 0 关注
  • 1960 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信