RE: [css-om] CSSStyleDeclaration.isReadOnly

> What's the use case?

Again, I want to add CSS properties to the browser as part of a polyfill so I need to know whether my getter should return a "inline style" value or compute the actual value of the property (getComputedStyle).




> This can trivially be checked already, e.g. by using:
>
> function isReadOnly(decl) {
> try {
> decl.setProperty('', '');
> } catch(e) {
> return true;
> }
> return false;
> }

This is mostly what I do, but I call this a work-around. This is seriously ugly (not to mention relying on exceptions is probably slow and triggers false alerts when you debug and set the parameters to "break on all exceptions"). 

I also had the idea to rely on some property no one use (clip) and call the object read-write if it has the "" value, because this can't possibly happen if the object returns the computed style, but the error-checking stuff still has to happen because it could either be a computed value or someone actually using the property.




> Is it common to check for this?

If you're not extending the CSSStyleDeclaration interface, I guess it's not. You know whether you just called .style or .currentStyle/getComputedStyle. If you only have a reference to the CSSStyleDeclaration object and want to call the right getter/setter depending on what it does, it is. 		 	   		  

Received on Thursday, 22 August 2013 16:54:46 UTC