Function Constructors as a type?

Brendan Eich brendan at mozilla.org
Tue Jun 26 14:01:06 PDT 2007


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/).

/be

On Jun 26, 2007, at 1:51 PM, Kris Zyp wrote:

> 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 t he current reference  
> implementation goes into an infinite loop when this is executing, I  
> assume that is not the intended behavior :).
> Kris
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20070626/8e293b5d/attachment-0002.html 


More information about the Es4-discuss mailing list