Optional argument types

Rick Waldron waldron.rick at gmail.com
Mon Sep 24 11:13:09 PDT 2012


On Mon, Sep 24, 2012 at 1:40 PM, Dmitry Soshnikov <
dmitry.soshnikov at gmail.com> wrote:

> Hi,
>
> Just a curiosity -- what is the current state of the optional argument
> types proposal (if there is one)? Isn't it too late to propose?
>
> Just recently participated in a discussion when these optional types are
> wanted to be used. Having a build-tool with pre-processing it's not that
> hard to add them manually to our sources, of course e.g.
>
> function foo(/*string*/ bar, /*number*/ baz) { ... }
>
> We could even add a small language extension having such preprocessors --
> instead of comments use real keywords/constructor names:
>
> function foo(String bar, Number baz) { ... }
>
> If these are constructor names, then even new keywords are not needed, and
> the code just translates into:
>
> function foo(bar, baz) {
>   if (typeof bar != 'string') throw TypeError(...);
>   if (typeof baz != 'number') throw TypeError(...);
> }
>
> That's it, literally it does only this and nothing else.
>
> (Instead of `typeof` can be used [[NativeBrand]] check of course)
>
> The same can go to the return values.
>
> This is _only_ for arguments, not simple variables may "carry type" (since
> these are the values carry types, not the vars), just simple runtime type
> checking in the prologue of a function.
>
> (I had have proposed similar before using JavaDocs instead
> https://gist.github.com/1186853, however, simple optional types could be
> better).
>
> Does JS need this much?
>
>

Check these out:

http://wiki.ecmascript.org/doku.php?id=strawman:guards
http://wiki.ecmascript.org/doku.php?id=strawman:trademarks

Rick


> Dmitry
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120924/ffb56412/attachment-0001.html>


More information about the es-discuss mailing list