Date.now is actually just a function (specified by ES5) which returns a new
date object of the current time, Number.random returns a new random number,
and String.uniqueID returns a new unique String.

So these functions return new stuff, rather than modifying stuff. Because
Date.now returns a Date object, it's on the Date namespace, same for
Number.random and String.uniqueID.
If it would be on the prototype, the API would be: new Date().now,
''.uniqueID() or (1).random() and as you can see it's not as pretty and
doesn't really make sense.


On Tue, Feb 8, 2011 at 1:22 PM, Savageman <[email protected]> wrote:

> Cool. You answered 2 questions in one, because that explains something
> else I wanted to ask: why Object doesn't get implement() but only
> extend(). Pointless now. ^^
> Plus, I'm starting to collect some interesting links / websites for
> further reading. Thanks for that!
>
> To continue on the same topic, here's my next question:
> Is there any reason Date.now(), Number.random() and String.uniqueID()
> are extended rather than implemented? (which means are part of the
> Date, Number or String namespaces rather than their prototypes).
>
> On 8 fév, 06:56, אריה גלזר <[email protected]> wrote:
> > One day I'll remember how to spell verboten by heart :)
> >
> > great thread btw - reading Moo's (or any library for that matter) source
> is
> > the most educating action any developer can take. It has improved my code
> by
> > a huge factor and it also helps a ton when you want to understand how
> > something works (I find myself going into the code - Class's particularly
> > once or twice a week [like reading a good book :) ])
> >
> > If it keeps developing as it did so far (it's all on you Savageman!) I
> > suggest we transform this into a blog post. This is simply priceless!
> >
> >
> >
> >
> >
> > On Tue, Feb 8, 2011 at 3:25 AM, Kilian C. <[email protected]>
> wrote:
> > > thaks Aaron for the link
> >
> > > On Tue, Feb 8, 2011 at 1:43 AM, Aaron Newton <[email protected]> wrote:
> >
> > >> The Number.prototype.$family is an excellent reason, indeed. Didn't
> > >>> catch my attention, oops! (I'll try to be more careful in the
> > >>> future...)
> >
> > >> No apologies necessary! I was just pointing out how you might figure
> it
> > >> out on your own. Teach a man to fish and all that...
> >
> > >>> Why Object.extend('forEach', [...]) instead of
> > >>> Object.implement('forEach', [...]). Or: why defining forEach as a
> > >>> property of Object rather than in it's prototype? Is it because
> > >>> everything is an object and we don't want other types to be "forEach-
> > >>> able"?
> >
> > >> Object (which is a function) .extend will add forEach to the Object
> > >> namespace. Object.implement will add forEach to the prototype (as you
> note).
> > >> Extending the object prototype is a *bad* idea. See:
> >
> > >>http://erik.eae.net/archives/2005/06/06/22.13.54/
> >
> > --
> > Arieh Glazer
> > אריה גלזר
> > 052-5348-561http://www.arieh.co.ilhttp://www.link-wd.co.il

Reply via email to