Andrea Giammarchi andrea.giammarchi at
Wed Feb 27 10:34:50 PST 2013

Surely already discussed, I forgot the outcome.

Why we have Array.isArray but not a more generic Function.isClassOf() ?

Here an absolutely not optimized idea of what I am talking about:

Function.prototype.isClassOf = function isClassOf(obj) {
  if (obj == null) return false;
  var Class = {};
  return Class == '[object ' + + ']' || (
    Class == '[object Object]' &&
    obj instanceof this

function UserDefined() {}

  Array.isClassOf([]), // true
  Object.isClassOf({}), // true
  Function.isClassOf(function(){}), // true
  Boolean.isClassOf(false), // true
  UserDefined.isClassOf(new UserDefined), // true
  Object.isClassOf([]) // false

If the answer is about not polluting prototypes, I wonder how many
developers out there for/in functions, 'cause if they do, they have to
check own property and remove 'length' and 'name' anyhow.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list