Prevent crashes in JavaScript Mode

Since JavaScript isn't already running with Processing v3.x, I use Processing v2.2.1 with JavaScript v0.3.3 to create a HTML export.

To prevent crashes I noticed that following Java code, which is running fine in other modes, is crashing with JavaScript.

void drawText(String text)    //---crashes!---
{ text (text, 10,20); }
void drawText(String aText)   //---is working fine!---
{ text (aText, 10,20); }

The reason is, that 'text' is used as input parameter and as function name too.

So to prevent crashes be careful at coding:

Do not use variable names that are equal to function names!

Please Florian can you warn coders to fall into this trap!

If you are able to correct this language parsing deficiency, it would be nice to have an updated version for Processing 2.x too!

In any case many thanks to you Florian for providing JavaScript mode for all processing addicted!

Best regards ;) Martin

Ps. Are there hope to provide JavaScript for in the meantime stable version of Processing v3.x ?

Tagged:

Comments

  • edited March 2016

    Since JavaScript isn't already running with Processing v3.x, ...
    Are there hope to provide JavaScript for in the meantime stable version of Processing v3.x?

    https://GitHub.com/fjenett/javascript-mode-processing/issues/33#issuecomment-146649518

    The reason is, that 'text' is used as input parameter and as function name too.
    If you are able to correct this language parsing deficiency,

    Some languages like Java, C, etc., just happen to have separate namespaces for variables & functions, so they can share the same name label.

    But even though we can have a variable called text and a function also called text(), it doesn't mean it's good programming to do so. [-X

    And a parse algorithm smart enough to pull that out is also über hard to come up with!
    So don't mix variable & function names, especially if you intend to make it cross-mode compatible w/ Java & JS modes. L-)

    BtW, other Java features which aren't correctly transpiled to JS is integral division and char datatype. :-\"

Sign In or Register to comment.