(Map|Set|WeakMap)#set() returns `this` ?
waldron.rick at gmail.com
Tue Dec 4 14:57:32 PST 2012
On Tue, Dec 4, 2012 at 3:50 PM, Brendan Eich <brendan at mozilla.org> wrote:
> The survey I'd like to see is among underscore, jQuery, and other popular
> libraries (go by NPM dependency frequency and client-side use frequency),
> how do set-like methods work: return-this or return-v?
underscore and jQuery side with
1. returning the calling object
2. returning a new object of the same "kind", but with the results of the
jQuery objects themselves are similar to a set, most operations on the set
itself result in returning a new jQuery object (set) that reflects the
results of the operation. As I explained previously, the reason it returns
a new jQuery object is to support the end() and addBack() methods by
storing the original as a property of the current, this that allows either
restoring the original set to it's pre-operation state or adding the
original set to the current set. If this were not an API that we supported,
jQuery could just as easily be a custom wrapper over an ES6 Set.
underscore actually has a special method called _.chain() that returns a
wrapped object that allows for chaining all of the underscore APIs—until
value() is called, which closely matches the examples I gave yesterday.
underscore has a _.defaults() function that returns the mutated object
after applying a default set of properties and values (similar to
_.extend()). There is no analogous Set api in underscore.
for npm in order of most dependencies:
1. underscore (see above).
- Any API that "sets" something, returns this (
- There is a lib that Mikeal also wrote "form-data" that has an append
method that does _not_ return this
3. async. Nothing comparable
- app.set, and subsequently all aliases, returns this (
- response.set, and subsequently all aliases, returns this (
- every operation that is not a "get" returns self as this; (
- nearly every operation that is not a "get" returns this; (
- setTheme returns the theme that was set
8. uglify. Nothing comparable
- Too much to review, but it's primary API that "sets" values, returns
this (see examples in readme)
- Too much to review, nearly everything returns this (
When I was researching whether or not it was worthwhile to pursue this
discussion, I reviewed most of this stuff, as well as web-focused libs.
At the moment I have to head out, so I can't continue to research this, but
I'll gladly spend as many hours as anyone thinks is necessary to prove my
> This is closer than a people-survey to mapping the cowpath.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss