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

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.

Received on Saturday, 30 July 2011 00:51:15 UTC