who needs social life when you have broadband?

Inventas vitam iuvat excoluisse per artes / Let us improve life through science and art.

Javascript 1.7 (or Pythonscript ?)

Hello! This topic will explain some of the new features of JavaScript 1.7 which are
embedded in Firefox 2.0 Beta1+ versions and probably in IE (I'm not sure).
The most interesting point in the new features is the "apparently" correlation
with the Python same features, which I will cite.
Well, let's prepare to use our new features. First of all, we need to declare some
special string in the script type attribute like that:

HTML:
  1. <script type="application/javascript;version=1.7"></script>

With this tag, we enable the v.1.7 features on our scripts.
This is needed because some new reserved keywords of 1.7 version may
interfere in the old code, the words are: "yield", "let", etc...
Let's begin.

Generators
Generator are like interactive functions with state variables.

JAVASCRIPT:
  1. /* The function */
  2. function gen()
  3. {
  4.     var i = 0;
  5.     while(true)
  6.     {
  7.         yield i;
  8.         i++;
  9.    }
  10. }
  11.  
  12. /* The "g" var isn't a simple function,
  13. is a instance of an generator */
  14. var g = gen()
  15.  
  16. /* This for loop show 3 alerts with
  17. respective values: 0, 1, 2 */
  18. for (var i=0; i&lt;3; i++)
  19. {
  20.     alert(g.next())
  21. }
  22.  
  23. g.close();

This is a powerful new feature of JavaScript 1.7, and have the same
syntax of Python Generators as you see here.

I will post about other new features in next posts, cause now I'm busy
with the Distributed Rainbow Tables project.

Farewell,
Christian S. Perone

No comments yet. Be the first.

Leave a reply