Number constructor has to exist to give access to the prototype which I agree 
isn't as useful in itself.  However, augmenting Array has several interesting 
uses.  The more I think about it, the more I see that the constructors and 
access to prototypes for the primitives helps maintain consistency across the 
language.  

-----Original Message-----
From: Lasse Reichstein [mailto:[email protected]] 
Sent: Friday, January 14, 2011 3:01 PM
To: [email protected]; Joel Dart
Subject: Re: [JSMentors] using new with Wrappers

On Thu, 13 Jan 2011 18:33:53 +0100, Joel Dart <[email protected]> wrote:

>> Why? Well, simply because that's how the specification says it should 
>> be.
>
> I'm taking a guess here, trying to justify this and would appreciate 
> feedback in my thinking.  Since new has to set up the prototype chain, 
> it would necessarily have to return an object since primitives do not 
> have properties and methods.  Does this sound right?

That doesn't explain the existence of Number as a constructor.
Built-in functions doesn't have to work as constructors, but Number does, and 
it was a deliberate choice.
I'm guessing it was intended to mirror Java's wrapper classes (Integer as 
wrapper for int, Long as wrapper for long, etc).
I.e., it's intended to make an object that represents the primitive value.
That made sense in Java, because you couldn't use objects and primitives 
interchangably, but it really doesn't make sense in JavaScript. Creating Number 
objects is pretty much useless. If you ever need an *object* that stores a 
number value, you can just create a custom object yourself and store the number 
value as a property - it's probably also better Object Oriented modelling than 
using a generic Number object with no inherent meaning in your model.

/L

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to