[[Class]] Property of Host Object

Garrett Smith dhtmlkitchen at gmail.com
Fri Jul 23 00:58:51 PDT 2010

On 7/22/10, Mark S. Miller <erights at google.com> wrote:
> On Thu, Jul 22, 2010 at 11:16 PM, David Flanagan
> <david at davidflanagan.com>wrote:
>> Allen,
>> The host vs. native distinction has long bothered me as well.  Thanks for
>> a
>> particularly lucid explanation.  In the next edition of the spec, perhaps
>> you could go further and eliminate the use of the word "host" altogether,
>> leaving you with only native objects and non-native objects.  Then you
>> don't
>> have to say that host objects can be native, or non-native.
>> Garrett,
>> You could drop the confusing word "host", too.  If you invert the boolean
>> sense of your function then you can call it isNativeObject() or
>> isNativeValue() or just isNative().

Changing the name would not make it interoperable with all released IE

The problem of isNativeObject can mostly be avoided.


> Fortunately, for this one, you can simply ask
>     typeof o === 'function'

Yes, and much shorter than David's example and it still only holds
true in ES5 implementations, so not interoperable.

The other consideration with David's example is if it is used with any
library that adds Array.prototype.forEach, and many do. In that case,
David's `isCallable` would return true for anything, even if it was
not passed anything at all:

Array.prototype.forEach = function(fun , context) {

Now most of the time, web sites check first, as the examples on MDC
have long advocated, however there are many copy'n'pastes of what I
see on Twitter.com. I've posted this on comp.lang.javascript -- have
you noticed this?


// Source code for Twitter.com:
if(!Array.forEach) {
  Array.prototype.forEach = function(D, E) {
    var C = E || window;
    for(var B=0, A = this.length; B < A;++B) {


The same strategy was copy'n'pasted to the company "CoTweet", also a
jQuery shop.

The source of this may be Twitter employee Dustin Diaz:
The code seen on Twitter.com looks strikingly similar, using `window`
as global object, using pre increment instead of post increment, not
checking to see if it is a sparse as if(`i in this`){ ... }, yet it is
different than Prototype's each.

And so using David's 'isCallable', we could have
var nothingIsCallable = isCallable(); // true on Twitter.com

Same problem with Function.prototype.bind checks:
function isCallable(obj) {
  try {
    Function.prototype.bind(obj, null);
    return true;
  } catch(ex) {
    return false;

Harmony should differentiate between non-native and native objects.

Constructs such as that should not be depended upon.


More information about the es-discuss mailing list