Fake Strong typing in Jscript

September 3rd, 2005 by Andrea Interguglielmi - Viewed 7744 times -




In my endless search for the best language to script my rigs, sometimes I discover new features of the languages I already use.

It happened again a few days ago, while I was reading through MSDN’s JScript reference to see why the “import” statement is protected, hoping again to find an include-like functionality that every JScript user misses and envies from python.

Of course, there wasn’t anything like that, the import statement seems to be protected for a future implementation of JScript, but I’ve found an interesting “Labeled Statement”…

As msdn reports:

Labels are used by the break and continue statements to specify the statement to which the break and continue apply.

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function labelDemo()
{
   Outer:
      for (i = 0; i < 5; i++)
      {
         Inner:
            for (j = 0; j < 5; j++)
            {  
               if (j == 2)
                  continue Inner;
               else
                  break;
            }
      }	
}

Unfortunately for my code, which now looks like an ugly Frankenstein, it is possible to use those labels everywhere in your code without warning the parser, which technique allows for things like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
Class: MyClass = function()
{
    Private:
    Int: var my_property;
 
    Public:
    String: this.MyProperty;
 
    Void: this.MyMethod = function()
    {
        // do something.
    }
}

It may be cool and improve readability, but it's difficult to maintain the code consistent because the parser will never warn us, even if we write Blablabla: var hello;.

To use it or not? what do you think?

Comments are closed.