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:
-
<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.
-
/* The function */
-
function gen()
-
{
-
var i = 0;
-
while(true)
-
{
-
yield i;
-
i++;
-
}
-
}
-
-
/* The "g" var isn't a simple function,
-
is a instance of an generator */
-
var g = gen()
-
-
/* This for loop show 3 alerts with
-
respective values: 0, 1, 2 */
-
for (var i=0; i<3; i++)
-
{
-
alert(g.next())
-
}
-
-
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
