Boolean objects in conditionals

Lasse R.H. Nielsen atwork at infimum.dk
Sat Nov 29 05:40:58 PST 2008


On Sat, 29 Nov 2008 01:15:53 +0100, David-Sarah Hopwood <david.hopwood at industrial-designers.co.uk> wrote:

> I think the problem is that wrapper objects exist at all, not any specific
> aspect of their semantics. There is no reason to have such wrappers in a
> language in which is is possible for a given variable to hold either a
> primitive value or an object reference. Programmers should simply avoid
> using them (except where they are created and immediately discarded as a
> result of calling a method on a primitive value)

It's a hassle on implementers that you have to create these implicit objects
at all, when they aren't needed most (99%) of the time. You still need to create
them for the last 1% of the cases, since user written methods can escape the object,
e.g.,
 Number.prototype.box = function() {
   return this;
 };
 var n = (42).box();

I would prefer to have "this" refer to a basic value instead when calling 
"methods on primitive values".
I.e.:
 (42).toString()
should not be equivalent to "new Number(42).toString()", but to something 
simliar to "Number.prototype.toString.call(42)" that actually uses "42" 
as the value of "this".

Alas, that's probably too big a change for 3.1 :(
/L
-- 
Lasse R.H. Nielsen
'Faith without judgement merely degrades the spirit divine'


More information about the Es-discuss mailing list