Chris said:
Yah, toString() still works fine. It's just not getting called when I
think it should.
Pardon?
element.style.backgroundColor = object.toString();
or
element.style.backgroundColor = String(object);
I really like the elegance of something like:
heading.style.color = myCalculatedColor;
Adding rgb() (which really is just an alias for toString()) probably
wasn't necessary; my intention was to add something a little easier to
type again and again than toString(), like using $() instead of
document.getElementById().
Your reasoning is not logical.
First, the use of identifiers starting with `$' should be restricted to
machine-generated identifiers per the Language Specification. Those who use
them anyway for other purposes have failed to notice or are deliberately
ignoring that, and the obfuscation and ambiguity and risk of being reused in
other contexts that comes with this short an identifier as `$'. See also my
signature.
Second, you are ignoring that you are dealing with a host object left-hand
side, so you can not expect universal automatic type conversion on the value
as the object's implementation may implement its [[Put]] algorithm as the
implementor saw fit.
Third, with implicit type conversion like above you require the definition
of another string value as defined in and, more important, the evaluation of
,-[ECMAScript Ed. 3 Final, section 11.6.1]
|
| [...]
| AdditiveExpression : AdditiveExpression + MultiplicativeExpression
which calls ToPrimitive(GetValue(AdditiveExpression)) and
ToPrimitive(GetValue(MultiplicativeExpression)) [steps 1. to 4.], then tests
the type of the results [4. and 5.], calls ToString() on them if they are
String [7.], applying ToString() to the each operand [12. and 13.], which
calls ToString(ToPrimitive(AdditiveExpression, String)) (section 9.8) which
in the end only calls ToString(AdditiveExpression.toString()) (sections 9.1
and 8.6.2.6).
So it strikes me as being much more efficient to call String() or (better,
but not always applicable) toString() directly.
PointedEars