在js中关于return this的问题

on: function(event, fn) {

    var handles = this._handles || (this._handles = {}),

      calls = handles[event] || (handles[event] = []);


    // 找到对应名字的栈

    calls.push(fn);


    return this;

  }

在这个函数中,return this到底是什么意思,调用这个函数的时候并没有和赋值语句一起使用啊?请问为何还要使用?



慕娘9325324
浏览 1961回答 1
1回答

天涯尽头无女友

如果你知道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 {}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript