Function Constructors as a type?

# Kris Zyp (18 years ago)

Is it possible to use a function constructor as a type? For example: function F() {} var f : F = new F; I assume this is not allowed, although I would think it would be nice if it were allowed, but I can't seem to find anywhere in the spec where this is explicitly stated and the current reference implementation goes into an infinite loop when this is executing, I assume that is not the intended behavior :). Kris

# Brendan Eich (18 years ago)

Functions are objects (instances), not types. Any new F given
function F(){} must return an Object, as in ES1-3.

You can write function types of course, they are structural types:

type F = function (int, double, string):Object;

The usual subtyping rules apply, with sane extensions for optional
and rest parameters. An update to spec/type_system.html is coming
soon, and look for spec/type_relations.html too (under http:// developer.mozilla.org/es4/).

# Kris Zyp (18 years ago)

Thanks Brendan, appreciate the help. Still curious though if anyone has an idea about how toJSONString should operate on mixed namespace objects though... Perhaps toJSONString will just use the identifier part of the name (leave out the namespace), and/or only use the names that have open namespaces and leave it to JSON extensions to attempt to serialize namespaces? Kris