How about a #typesafe or #allow-unsafe-js directive?

Topics: General, Language Specification
Dec 5, 2012 at 11:08 PM
Edited Dec 5, 2012 at 11:09 PM

There are some things that are very annoying with JavaScript.  For instance this piece of misery:

        if (id = 5) 

Do you see the mistake?  It took me a couple hours.  Yet C# would have flagged the "error" immediately.  Maybe if we had a #typesafe directive that would flag as errors things that are otherwise valid javascript.  Or conversely, maybe a #allow-unsafe-js directive would be better.

Dec 6, 2012 at 12:59 PM

JavaScript developers usually use linting tools like JSLint ( ) or JSHint (my preference - ) to catch these kinds of common errors.

Dec 6, 2012 at 9:06 PM
Edited Dec 6, 2012 at 9:08 PM

The idea was that the directive could do more than simple lint checking.

The directive solves the impedance mismatch between javascript and typesafe code.  For example, it could ensure that 'this.' always meant '_this.' in classes.