logoalt Hacker News

hax0ron3 • today at 8:32 PM • 3 replies • view on HN

Although jQuery isn't very relevant these days, I still find its pattern of chaining a sequence of methods on a set chosen by a selector to be a beautiful example of going with a language's features.


Replies

btown • today at 9:06 PM

To that point, there was a conscious choice that the return type of most method invocations (except in specific "read a value" modes) should be a standardized container type.

That was, and still is, rare! And in a time without type checking and bundling, it was vital. Match your parentheses and quotes, and your jquery code might not find what you want, but it would (likely) not throw exceptions.

For those unfamiliar, I recommend looking at https://github.com/DefinitelyTyped/DefinitelyTyped/blob/mast... and searching for the 201 instances of

    : this
in that file. A remarkably fluent API. We could all be so elegant.
paulddraper • today at 9:39 PM

This is called a fluent interface. [1] C++ streams are perhaps the most common example of this pattern.

A TC39 Stage 2 proposal adds this into the language itself with the pipeline `|>` operator. [2]

[1] https://en.wikipedia.org/wiki/Fluent_interface

[2] https://github.com/tc39/proposal-pipeline-operator

embedding-shape • today at 8:54 PM

Are you talking about method chaining, something that comes from JavaScript (technically the DOM I suppose), not jQuery?

➕ show 3 replies