Create chained methods in node.js?

后端 未结 2 761
一个人的身影
一个人的身影 2021-02-10 02:44

Is it possible to create chained methods that are asynchronous like this in node.js

File.create(\'file.jpg\').rename(\'renamed.jpg\').append(\'Hello World\')
         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-10 03:02

    Sure, like any JavaScript, you just return an object that has that method.

    One possible layout (among many).

    var File = new (function() 
    { 
      this.create = function(str) 
      { 
        return this; 
      } 
      this.rename = function(str) 
      { 
        return this; 
      } 
    })(); 
    

提交回复
热议问题