Skip to content

Instantly share code, notes, and snippets.

@iros
Created May 22, 2012 21:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iros/2771685 to your computer and use it in GitHub Desktop.
Save iros/2771685 to your computer and use it in GitHub Desktop.
Thoughts on Chaining
var el = $('div.button');
// is this bad? I'd think so:
el.addClass('closed').css('border', 'none').attr('x', 5);
// first method call in line, subsequent below indented?
el.addClass('closed')
.css('border', 'none');
// context switching adds indentation? (like in d3)
var chart = d3.select('ul')
.append('ul')
.data(myData)
.enter()
.append('li')
.text(function(d) {
return d.value;
});
@iros
Copy link
Author

iros commented May 22, 2012

Questions:

  1. How many chained methods before it's too many?
  2. Should you chain at all?
  3. Should you ever chain if context switch happens?

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