Le 13 janv. 2014 à 11:45, Anne van Kesteren <[email protected]> a écrit :
> In a discussion I had with Alex Russell as how to do comparison for > URL objects it ended up with desiring > > url == url2 > > to work. It escaped me at that point that I already discussed this > briefly and Brendan explained why face-to-face. However, I forgot what > he said :/ > > The alternative, either something like > > url.equals(url2) > > or > > URL.equal(url, url2) > > or > > url.toString() == url2.toString() > > is somewhat Java-esque. Is that what we should do? And if so, opinions > on which variant? > > > -- > http://annevankesteren.nl/ > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss Consider the following objects: url, url2, ... : URL objects location, location2, ... : Location objects a, a2, .... : HTMLAnchorElement objects All these objects implement URLUtils according to the WhatWG specs, and are therefore stringified using their `href` attribute. Now, which one of these equalities should "work" by just comparing the stringification? url == url2 location == url location == location2 a == url a == location a == a2 For me, I couldn't say. But in any case, my intention is clearer (and not too Java-esque) by writing the following: a.href == location.href In the worst case, when I don't know if I have a string or an URLUtils object, I just ensure that at least one member of the equality operator is stringified—and, most importantly, that it is evident from reading my code that one member is stringified: a.href == url String(whatever) == url —Claude _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

