Math doesn't like prototyping because its a "library" of static
methods, always invoked as such "Math.floor(num)".  You never see
"myMath = new Math()" so there is your prototyping issue.

Also this approach seems very odd to me, such a simple inequality
seems absurd. Given your example, and granted you properly integrated
this with the number class, how much does the implementation benefit?

if(num.sign() == -1)  vs if (num < 0)

if(num.sign() == 0) vs if (num == 0)

if(num.sign() == 1) vs if (num > 0)

Seeing this laid out as such kind of illustrates my point. The
implementation could perhaps be simplified if you went with a simpler
method. Such as "isPositive" or "isNegative", even that seems a bit
much but.. good luck!




On Feb 2, 10:22 am, "Deniz Adrian" <[EMAIL PROTECTED]>
wrote:
> To me this seems like no win. What do you need that for?
>
> On Feb 2, 2008 5:20 PM, Sascha Leib <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hello all,
>
> > after I spent two days trying to find something like "Math.sign()" or
> > similar in core JavaScript, I decided that quickly writing it myself
> > would probably be smarter (in terms of time management at least ;-)
>
> > Now, this is really pretty straightforward:
>
> > > Number.prototype.sign = function() {
> > >       if(this<0){return -1}
> > >       else if(this>0){return 1}
> > >       else {return 0};
> > > };
>
> > But I somehow still can't believe that this is neither in JS nor in
> > Prototype implemented...
>
> > Now, did I just miss sth., or is it so rarely needed that nobody ever
> > missed it - or do you think it should be added to Prototype?
>
> > /sascha
>
> > PS: Oddly, the "Math" class doesn't seem to like 'prototyping'. -
> > well, "Number" is the better choice anyway...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to