[whatwg] Microdata - Handling the case where a string is upgraded to an object

Some IRC discussion this morning concerned the scenario where an API
starts by exposing a property as a string, but later wants to change
it to be a complex object.

This appears to be a reasonably common scenario.  For example, a
vocabulary with a "name" property may start with it being a string,
and then later change to an object exposing "firstname"/"lastname"/etc
properties.  A vocabulary for a music library may start by having
"track" as a string, then later expanding it to expose the track
title, the individual artist, the running time, etc.

In a very similar vein, the CSSOM is currently defined to always
return property values as strings.  We want to instead return complex
objects that expose useful information and interfaces specialized on
the value's type, however.  For compat reasons, we have to use an
entirely different accessor in order to expose this type of thing.

It seems that this may be a useful problem to solve in Microdata.  We
can expose either an attribute or a privileged property name for the
object's "name"/"title"/"string representation".  Then, when using the
.items accessor, objects can be returned with a custom .toString that
returns that value, so they can be used as strings in legacy code.

Thoughts?

~TJ

Received on Thursday, 14 July 2011 11:49:44 UTC