On Jul 9, 2011, at 8:48 AM, Brendan Eich wrote:

> See above, there is nothing novel or evil in isName or isArray (another 
> example) isGenerator.

Also the Proxy.isTrapping, which in recent threads has been proposed to be 
renamed to Proxy.isProxy or Object.isProxy.

This is a fine point, but we may as well hash it out, and es-discuss is the 
best place: do we want Object.isFoo predicates, in spite of precedent such as 
ES5's Array.isArray (which I've whined about as redundantly and a bit 
misleadingly named, since its argument can be any value -- Object seems a 
better home, lacking a Value "class" built-in constructor in which to bind 
Value.isArray).

Back at the dawn of time, isNaN and isFinite as value predicates. Not relevant, 
since not type predicates, but worth a mention. ES.next adds saner (no argument 
coercion) Number.is{NaN,Finite} predicates, and Number.isInteger for testing 
whether a number is an integral IEEE 754 double.

For ES.next, Function.prototype.isGenerator has been proposed (and implemented 
in Firefox 4 and up).

Why not Function.isGenerator? Because the prototype method is more usable when 
you have a function in hand and you want to know whether it's a generator. If 
you have any value x, you'll need (typeof x === 'object' && 'isGenerator' in x) 
guarding the x.isGenerator() call, but we judged that as the less common 
use-case.

Could be we were wrong, or that being consistent even in the hobgoblin/foolish 
sense is better. But Object.isGenerator crowds poor Object more.

Notice how there's no need for Function.isFunction or Object.isFunction, due to 
typeof (function(){}) === 'function'. That's another dawn-of-time distinction 
that does not fit the primitiive types vs. object classification use-case I 
mentioned in the last message -- testing whether x is callable via typeof x === 
'function', at least for native if not host objects, is the use-case here.

Some of these questions are at this point more about aesthetics and Principles 
than about usability. And we have historic messiness in how things have grown.

Given Array.isArray, perhaps we are better off with Proxy.isProxy. The case for 
Function.prototype.isGenerator hangs on usability, so I'd like to let the 
prototype in Firefox ride for a bit.

If someone wants to propose a better, extensible and uniform system of type 
predicate naming, please do.

/be
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to