- From: Garrett Smith <dhtmlkitchen@gmail.com>
- Date: Fri, 24 Feb 2012 10:05:02 -0800
- To: "Tab Atkins Jr." <jackalmage@gmail.com>
- Cc: public-script-coord@w3.org
On 2/23/12, Tab Atkins Jr. <jackalmage@gmail.com> wrote: > For context, the CSSStyleDeclaration interface defined at > <http://dvcs.w3.org/hg/cssom/raw-file/tip/Overview.html/#the-cssstyledeclaration-interface> > currently explicitly lists the supported CSS properties as attributes > on the interface. This list is obviously incomplete, and basically > required to be so, unless we force every CSS spec to apply deltas to > this interface just to add their properties. > > I had thought that the best way to fix this would be by using WebIDL's > getter/setter/etc special operations, simply defining that the list of > supported property names is the names of all the properties that the > browser supports (suitably transformed from dashes to camelcase, and > with the rare explicit exception like cssFloat). > > However, it was pointed out that this would produce a change in > behavior. The current definition puts all the properties on the > prototype object, while using getter/setter instead makes them own > properties, which in general means they would be put on the object > itself. The [NamedPropertiesObject] extended attribute makes them not > own properties again, but that's marked as deprecated and only to be > used for legacy behavior. > No, using getter/setter instead does not mean that the properties are "own". In fact, it is often the case where an object's getter or setter resides on the prototype chain. For example, the style property, in Gecko is a getter on the prototype chain:- document.body.hasOwnProperty("style");. HTMLElement.prototype.__lookupGetter__("style") === document.body.__lookupGetter__("style"); The `body` element's `style` getter is on `HTMLBodyElement.prototype`. var bodyp = HTMLBodyElement.prototype; var bs = Object.getOwnPropertyDescriptor(bp, "style"); bs.get === document.body.__lookupGetter__("style"); Looks like they've created a differet `style` getter for different implementations of `HTMLElement`. var divp = HTMLDivElement.prototype; var divpStyle = Object.getOwnPropertyDescriptor(divp, "style"); var div = document.querySelector("div"); divpStyle.get === div.__lookupGetter__("style"); Interesting, but beside the point. Point is, a getter doesn't have to be an own property. In contrast, it usually isn't. > What's the reasoning for this behavior difference between the two methods? > > If there's a good reason, what's another good way to solve my > use-case? Aryeh Gregor suggested just adding some text to CSSOM that > says that when CSS defines a new property it implies WebIDL like > "partial interface CSSStyleDeclaration { attribute DOMString newProp; > };" with the appropriate behavior definition. > For style properties unique to a type of element? Create an interface and then put those extras on the interface. For example, for a hypothetical SOUND element: CSSStyleDeclarationSound { attribute long volume; } -- Garrett Twitter: @xkit personx.tumblr.com
Received on Friday, 24 February 2012 18:05:31 UTC