Skip to content

Instantly share code, notes, and snippets.

@seoh
Created August 26, 2015 04:13
Show Gist options
  • Save seoh/5aff82d4d6f0603ff7d7 to your computer and use it in GitHub Desktop.
Save seoh/5aff82d4d6f0603ff7d7 to your computer and use it in GitHub Desktop.
kinds of chaining-indentation
/**
* so many type of chaining
*/
//// about dot-indentation.
// type 1-1. align with dot.
const ret = obj.method1()
.method2()
.method3()
.value();
// type 1-2. just indent
const ret = obj.method1()
.method2()
.method3()
.value();
// type 1-3. align with subjective obj.
const ret = obj.method1()
.method2()
.method3()
.value();
//// about assign indentation
// type 2. = isn't mine.
const ret =
obj.method1()
.method2()
.method3()
.value();
//// about block indentation
// type 3-1.
const ret = obj.method1(arg => {
// do something
})
.method2(arg => {
// do something
})
.value()
// type 3-2. saving lines.
const ret = obj.method1(arg => {
// do something
}).method2(arg => {
// do something
}).value()
@haruair
Copy link

haruair commented Aug 26, 2015

//// Aligned by parenthesist
const ret = obj.method1()
               .method2()
               .method3()
                 .value();

@seoh
Copy link
Author

seoh commented Aug 26, 2015

// align by semantics such as in d3.
const ret = obj.method1()
               .method2()
                 .style1()
                 .style2()
               .method3();

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