How are input parameters filled in javascript method chains?

后端 未结 4 1599
终归单人心
终归单人心 2020-11-28 11:50

I am trying to really understand the details of how javascript works. During method chaining, sometimes one method returns to another method that has a named input parameter

4条回答
  •  生来不讨喜
    2020-11-28 12:23

    If I understand correctly

    what does this data refer to? How is it filled?

    You mean how it works? It depends on how the callback gets called. For example:

    function Lib() {}
    
    Lib.prototype.text = function(callback) {
      var data = 'hello world';
      callback(data); // `data` is the first parameter
      return this; // chain
    };
    
    var lib = new Lib();
    
    lib.text(function(data){
      console.log(data); //=> "hello world"
    });
    

提交回复
热议问题