Sam Stephenson a écrit :
> I think I like the "Object.isArray" style best so far.  We must be
> careful with names like "Object.class", though -- "class" is reserved
> as a future keyword[1] by the ECMAScript spec.

I would vote for Object.isXxx too.  I don't quite see the usefulness of
introducing is.xxx if we're inside Object already and I like the
readability of Object.isXxx(obj).  OTOH, I don't like the feel of $is or
$t/$T.

I do advocate we use ==/==== over constructor functions whenever
possible.  I propose to provide the following at least:

        isArray, isUndefined, isDefined

Something along these lines:

Object.extend(Object, {
  isArray: function(o) { return (o) && (o.constructor === Array); },
  isUndefined: function(o) { return undefined === o; },
  isDefined: function(o) { return undefined !== o; }
});

(I use === on constructors because it's as good for our purposes as ==,
and possibly infinitesimally faster, as it doesn't have to account for
implicit conversions)

So for our common testing purposes, we get something like:

        someArg = Object.isDefined(someArg) ? someArg : defaultValue;

Slightly verbose, but we can go for consistency across the whole lib,
and it's eminently readable.

I would like to see a isEnumerable, but this can be a problem: what
should we test for?  Enumerability, so far, is obtained through "mixing
in" methods.

But then, this would be time-consuming and non-authoritative, checking
that all methods in Enumerable exist in the object (plus, either we go
by name, to account for overrides, but then we're not authoritative, or
we go by function comparison, but then we break on overrides, and Array
would not match).

Checking for _each seems insufficient as well.  I don't see an easy way,
so unless someone thinks of something brilliant, we might have to forego
isEnumerable :-/

-- 
Christophe Porteneuve a.k.a. TDD
"[They] did not know it was impossible, so they did it." --Mark Twain
Email: [EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
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