Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6907973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:30:08+00:00 2026-05-27T08:30:08+00:00

I noticed the following pattern in socket.io-node : // e.g. 1 socket.volatile.emit(‘bieber tweet’, tweet);

  • 0

I noticed the following pattern in socket.io-node:

// e.g. 1
socket.volatile.emit('bieber tweet', tweet);

// e.g. 2
socket.broadcast.json.send({ a: 'message' });

more generally, it seems to be of the style:

someObject.functionFlagA.functionFlagB.functionFlagEtc.someFunction(/* etc */);

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?

Looking at it gave me the idea of creating a sync object for my HTML5 web app like so:

// Saves someObj to localStorage AND to server-maintained session
sync.toLocalStorage.toServer.save(someObj);

…since it would be more self-documenting than:

// Saves someObj to localStorage AND to server-maintained session
sync.save(someObj, true, false, true);

Is this an appropriate use of above pattern?


EDIT 2011-12-06 13:06:15

For the curious, this is how socket.io implements it:

Socket.prototype.__defineGetter__('volatile', function () {
  this.flags.volatile = true;
  return this;
});

Which is used in chain to ultimately call the following internal function which sends a packet and clears the flags:

Socket.prototype.packet = function (packet) {
  /* snip */
  this.setFlags(); // clears this.flags

  return this;
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:30:08+00:00Added an answer on May 27, 2026 at 8:30 am

    I would call it an example of a fluent interface.

    From the Wikipedia article:

    In software engineering, a fluent interface (as first coined by Eric
    Evans and Martin Fowler) is an implementation of an object oriented
    API that aims to provide for more readable code. A fluent interface is
    normally implemented by using method chaining to relay the instruction
    context of a subsequent call.

    Of course in your example you have properties instead of methods. But looking at the socket.io-node code, the ‘properties’ are programmed as __defineGetter__ so you might as well say they are methods.

    With regards to your sync object for HTML5: think about the state of the sync object after calling save. Is it reset to its original state or does it remember the configuration? What happens if you call save twice in a row?

    If it’s just about readability, you can also have callers pass in the configuration like so:

    sync.save(someObj, { toLocalStorage: true, toServer: true });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've noticed the following pattern recently, but I don't entirely grasp the usage of
After over a decade of C/C++ coding, I've noticed the following pattern - very
I've been teaching myself Objective C recently, and have noticed the following pattern used
I was writing a pluginable function when I noticed the following behavior (tested in
I've been playing around with Spring Security a bit and noticed the following oddity.
I noticed C++ will not compile the following: class No_Good { static double const
I noticed for a while now the following syntax in some of our code:
I noticed using task manager that the following code has a GDI leak in
Noticed this today when a patch was submitted with the following line: lblCompletionTime.Text =
I've noticed that PHPmyAdmin creates the following SQL for table creation: CREATE TABLE something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.