On Feb 8, 12:55 am, Jim Higson <j...@333.org> wrote:
> alert( Object.isString( "foo" ));
> // alerts "string"

It alerts true.

> alert( Object.isString( new String( "foo" ) ));
> // alerts "object"

It alerts false.

> I know why this happens - because Prototype uses the underlying typeof's
> understanding of type.

That typeof returns the type is pretty reasonable given that it is
called "typeof".

> Personally I think this is a bug though - Javascript is just being difficult
> here

It's a bit unfair to blame the language for what you consider an
inappropriate use of one of its features.  Perhaps the name of the
function should be "isStringPrimitive".

> and Prototype should make stuff like this easier. It should
> return "string" regardless of how the string was created.

It is extremely rare to come across a String object in javascript, so
there seems very little point in an isString function when the vast
majority of the time a typeof test is sufficient (and less

In the unlikely event that you want to know if the thing you have is a
String object, use instanceof.  What is the use of an isString
function that can't tell the difference between an object and a

I can't conceive of a scenario where a String object would be used and
I'd get into a situation where I needed to test for something that was
either an object or a string.  If it doesn't matter, why use an
object?  And if it did matter, I'd want to test for one or the other
in which case neither the current isString or your suggested
modification would do the job.

Perhaps is should return one of three values: primitive, object or
boolean false.  Then if you don't care, you can use use:

  if (isString(...)) ...

as either 'object' or 'primitive' will resolve to true, but boolean
false will be false.

If you do care, you can use:

  if (isString(...) ==  'primitive') ...

The bottom line is to look at why you would use such a function, and
whether there are already suitable language features that do the job.

> Anyone agree I should file this as a bug, or is there a good reason the
> current behaviour is desirable?

It can hardly be called a bug when it does what the documentation says
it does (I think "works as designed" is the polite response).  The
function itself is a bit pointless though, as are similar functions
like isNumber, e.g.

  Object.isNumber(NaN); // true


  var x = 'a' * 2;
  Object.isNumber(x) );  // true

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to