title: Chain class methods with callbacks?
body: <p>In Node.js, how do you chain class methods together, when it's best practice to use callbacks? </p>
  
  <p>In my PHP days, I would typically do something like this:</p>
  
  <pre><code>class MyClass {
  
    function get() {
      // fetch some data from an API endpoint
      return this;
    }
  
    function set(property, value) {
      // Set the property to some value on the object
      return this;
    }
  
    function save() {
      // Save the data to database
      return this;
    }
  }
  
  $myObject = new MyClass();
  $myObject-&gt;set('something','taco')-&gt;save();
  </code></pre>
  
  <p>This very common OO approach allowed you to chain methods together as many times as you wanted.</p>
  
  <p>When working with Node.js, can you still somehow do chaining similar to this? Or do you just end up in callback hell? Every single "chain" is a nested callback? </p>
  
  <p>Or do I simply need to wrap my script in Promises?</p>
  
  <pre><code>new Promise(function(resolve, reject){
    var myObject = new MyClass();
    myObject.set('something','taco');
    resolve(myObject);
  }).then(function(myObject){
    myObject.save();
  });
  </code></pre>
  
  <p>Is that how you are supposed to do it? Is there any way to integrate this more deeply into my class so I don't have to wrap it in promises every time? I've seen some libraries have sort of a "promise-mode" like <a href="https://github.com/sindresorhus/got" rel="nofollow">https://github.com/sindresorhus/got</a> but after looking at the code I'm still not exactly sure how they did it.</p>