On Thu, Jan 13, 2011 at 6:33 PM, 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?
>
> Well, you're correct, although I wouldn't have put it like that. But yes,
`new` returns a new object so it makes sense to return a new object on
built-on objects as well.

The reason I said that in this case is because there's a difference between
doing `Number(2)` and `new Number(2)`. The difference, as literally laid out
in the specification, is that calling Number as a function (so without new)
will return a primitive whereas calling it as a constructor (with new) will
return a new object. Since he asked about the difference between Number and
new Number, that seemed to be what he was looking for. :)

- peter

-- 
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