Skip to content

Instantly share code, notes, and snippets.

@cowboy
Last active February 25, 2020 20:54
Show Gist options
  • Save cowboy/d29d24f3dbfb26cc33aa to your computer and use it in GitHub Desktop.
Save cowboy/d29d24f3dbfb26cc33aa to your computer and use it in GitHub Desktop.
JavaScript: chained method indentation
// Inspired by the eslint-plugin-react wrap-multilines rule
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md
//
// I don't know why, but this is making me really happy right now.
// Instead of this
var someName = namespace.someObj.method1({
prop: 'value',
}).method2('foo', 'bar');
// Or this
var someName = namespace.someObj
.method1({
prop: 'value',
})
.method2('foo', 'bar');
// Do this
var someName = (
namespace.someObj
.method1({
prop: 'value',
})
.method2('foo', 'bar')
);
@cowboy
Copy link
Author

cowboy commented Oct 15, 2015

The parens aren't required, I just like how they feel like a visual "container" to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment