why go throw all this complexity when javascript has a native isNaN function...


On Wed, Oct 8, 2008 at 6:40 PM, Tom Gregory <[EMAIL PROTECTED]> wrote:
>
> Thanks for the reply.
>
> I realize I don't get a vote here, but IMHO it either needs to be a)
> well documented that Object.isNumber( new Number(5) ) returns false,
> or b) support the Number class.
>
> The trouble with the name "isNumber" is that it's ambiguous--it can
> mean equally "is a number" or "is a Number" thanks to our camelCase
> conventions.
>
> ... and while you're correct that instanceof creates cross-frame
> issues, perhaps something like this might work (I haven't tested this
> in a cross-frame way):
>
> isNumber: function(object) {
>     return (typeof object == 'number') || (object.constructor ==
> Number.prototype.constructor);
>   }
>
> ... although IIRC, comparing constructors and prototypes across frames
> may not work ... what about converting the constructors to strings,
> then comparing them?  e.x.
>
> isNumber: function(object) {
>     return (typeof object == 'number') ||
> (object.constructor.toString() ==
> Number.prototype.constructor.toString());
>   }
>
> The following may also work, but is a bit looser in returning true
> values:
>
> isNumber: function(object) {
>     return (typeof object == 'number') || (object.valueOf && typeof
> object.valueOf() == 'number');
>   }
>
> Or, you could address the problem in a way similar to how Prototype
> does browser detection, by checking for the existence of specific
> properties (e.g. toExponential,  toFixed)
>
> I guess my point is there are enough smart people here that the issue
> could be solved.  I'm not wedded to having isNumber return true for
> Number objects (so long as it's clearly documented), but I do think
> such a decision violates POLS, and flies in the face of self-
> documenting code/descriptive function names.  (btw, the same applies
> for isString, etc.)
>
>
> TAG
>
> On Oct 7, 2008, at 1:55 PM, kangax wrote:
>
>>
>> On Oct 7, 11:17 am, Tom Gregory <[EMAIL PROTECTED]> wrote:
>>> How 'bout POLS?
>>
>> It's a bit hard to tell what "intuitive" definition of "number" is in
>> a weakly typed language. According to ECMA-262 specs, an object
>> created with `new  Number` is not of type number but rather of type
>> object. Besides somewhat moot type definition in JS, adding
>> `instanceof` check introduces notorious cross-frame issues. Taking
>> care of those issues results in additional complexity (just for the
>> benefit of taking care of edge cases).
>>
>>>
>>> TAG
>>
>> --
>> kangax
>> >
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" 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/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to