4 ms·
I've always thought the chaining methods thing that jQuery popularized was a pristine example of an anti-pattern. It might save a few keystrokes, but I questio
by wavephorm 15y ago
I've always thought the chaining methods thing that jQuery popularized was a pristine example of an anti-pattern. It might save a few keystrokes, but I question whether anyone really writes code like this the first time through. I suspect people actually take perfectly fine working code and refactoring it into a chain just to make the code appear more clever, all the while making the code harder to read and debug.
- deleted 15y ago[deleted]
- tikhonj 15y agoI like chaining because it emphasizes that a set of method calls is part of one discrete action involving one object. For example, take adding a header to some text: it's one action, but it involves multiple steps. First I create the actual element, then I give it a class name, add some text and finally insert it in the DOM. I think chaining not only makes the code easier to read (and type, although that isn't particularly important), but also makes its semantics clearer.
- wavephorm 15y agoThat's what functions are for. Chainable methods don't make multiple step operations more concise.