Object.prototype.equals

# Garrett (18 years ago)

Jason Orendorff wrote:

# Lars T Hansen (18 years ago)

On 7/16/07, Garrett <dhtmlkitchen at gmail.com> wrote:

Jason Orendorff wrote:

On 7/13/07, Garrett <dhtmlkitchen at gmail.com> wrote:

For collections, it would be very useful to have a natively-supported equals() method.

ECMAScript 4 has operator overloading. You can just override the == operator.

It would also be very useful to have native collections. Object and Array are limited.

J: What limitations are you referring to?

SortedSet is kind of a pain to hand-write in JavaScript and you have to check type every time. This won't change in ES4; typed arrays have been dropped.

Typed arrays have not been dropped, but they are in flux, so there's nothing on the public wiki about them at this time.

I hope you don't expect ES4 to provide all the data structures you need out of the box. The language actually targets fairly limited devices too. Opera's been running on very small machines for a long time already, and it should not be necessary these days to mention iPhone and Webkit :-) We are trying to keep things under control.

For SortedSet, operations can execute more quickly than with n-time Array lookups like with anArray.indexOf.

Method equals would be useful for a SortedSet. You could easily use valueOf or a comparator to compare the two objects for add/remove type of operations, but for something like a set of case-insensitive strings, overriding equals for the CaseInsensitiveString class would make it easier for contains type of operations.

I am understanding now that ES4 allows for operator overloading. Thank you. It would be nice to have collections to rely on a common interface for objects. I think equals method would be a good compliment to the existing valueOf method.

I'm inclined to agree, though there might be issues with backwards compatibility. We can't break the web.

J: ECMAScript 4 adds new Array methods, a new "for each" statement, and probably a standard Dictionary class.

I did not see the Dictionary class definition. in the spec here: (long, 1-page: www.mozilla.org/js/language/es4.html#formal_parser-grammar_N-FunctionExpression )

Also not on the public wiki yet, though on the agenda for this week's meeting.