title: Passing flags for functions via accessors - which JavaScript pattern is it?
body: <p>I noticed the following pattern in <a href="https://github.com/LearnBoost/socket.io" rel="nofollow">socket.io-node</a>:</p>
  
  <pre><code>// e.g. 1
  socket.volatile.emit('bieber tweet', tweet);
  
  // e.g. 2
  socket.broadcast.json.send({ a: 'message' });
  </code></pre>
  
  <p>more generally, it seems to be of the style:</p>
  
  <pre><code>someObject.functionFlagA.functionFlagB.functionFlagEtc.someFunction(/* etc */);
  </code></pre>
  
  <p>What is this pattern called, where you add flags which may affect the execution of a function, in a chain of accessors which each return the target function (with any other available/appropriate chainable accessors)? When is it appropriate over, say, just passing some parameters to a function?</p>
  
  <p>Looking at it gave me the idea of creating a <code>sync</code> object for my HTML5 web app like so:</p>
  
  <pre><code>// Saves someObj to localStorage AND to server-maintained session
  sync.toLocalStorage.toServer.save(someObj);
  </code></pre>
  
  <p>...since it would be more self-documenting than:</p>
  
  <pre><code>// Saves someObj to localStorage AND to server-maintained session
  sync.save(someObj, true, false, true);
  </code></pre>
  
  <p>Is this an appropriate use of above pattern?</p>
  
  <hr>
  
  <p><strong>EDIT 2011-12-06 13:06:15</strong></p>
  
  <p>For the curious, this is how socket.io implements it:</p>
  
  <pre><code>Socket.prototype.__defineGetter__('volatile', function () {
    this.flags.volatile = true;
    return this;
  });
  </code></pre>
  
  <p>Which is used in chain to ultimately call the following internal function which sends a packet and clears the flags:</p>
  
  <pre><code>Socket.prototype.packet = function (packet) {
    /* snip */
    this.setFlags(); // clears this.flags
  
    return this;
  };
  </code></pre>