[whatwg] link.sizes and [PutForwards=value]

On Sat, 30 Jul 2011, Cameron McCormack wrote:
>
> Jumping in the middle of this thread to pick up on one aspect...
> 
> On 28/07/11 6:15 PM, Ian Hickson wrote:
> > Are we really concerned about objects stringifying to "[Object Foo]"?
> > 
> > It seems that the usefulness of such stringification is far outweighed by
> > the usefulness of being able to treat the attribute as a string attribute
> > like any other reflecting attribute while also being able to use methods
> > on it. In fact, it is consistent with every DOMString attribute: they
> > don't stringify to "[Object String]", yet you can call methods on them.
> > What's the difference?
> 
> There is a disadvantage.  In JS, doing a comparison between two objects,
> regardless of whether they have custom stringification behaviour, will compare
> based on object identity and not the string.
> 
> <!DOCTYPE html>
> <iframe id=x src=b.html></iframe>
> <iframe id=y src=b.html></iframe>
> <script>
> window.onload = function() {
>   var xw = document.getElementById("x").contentWindow;
>   var yw = document.getElementById("y").contentWindow;
>   alert([xw.location, yw.location,
>           xw.location == yw.location].join("\n"));
> };
> </script>
> 
> The two Location objects stringify to the same thing, but are not ==.  I think
> this can be confusing.

Can we overload equality for objects?


On Tue, 2 Aug 2011, Cameron McCormack wrote:
> On 2/08/11 6:29 AM, Tab Atkins Jr. wrote:
> > It's a confusion shared by all objects, though:
> > 
> > var x = [1,2];
> > var y = [1,2];
> > alert([x,y,x==y).join(' ');
> > 
> > This alerts "1,2 1,2 false".
> 
> That is true, but I get the impression that some authors don't know that 
> the Location object is actually an object rather than a string.
> 
> I don't feel like [PutForwards] is a particularly obvious API design 
> pattern for authors, and I don't think we should be adding new uses of 
> it.

I think the benefits outweigh the disadvantages here. With most cases of 
DOMSettableTokenList, it doesn't make sense to do a straight comparison 
anyway -- a sizes="" attribute with value "10x10 20x20" should be 
considered equivalent to "20x20 10x10", even though they aren't equal.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Friday, 20 January 2012 15:49:35 UTC