Technical Committee 39 (TC39), which you may remember as the group inside of ECMA that first standardized ECMAScript, is still in charge of developing future editions.Like the first edition of ECMAScript, the fourth edition was first proposed by Netscape Communications, and TC39’s schedule originally called for its release in 2002.However, issues arose surrounding the clout that Microsoft had gained on the Web since the first edition of ECMAScript had been standardized.Microsoft entered its own proposal to TC39 for the future direction of ECMAScript.
TC39 changed the planned release of ECMAScript Edition 4 to the first quarter of 2004, almost two years later than the originally scheduled release. However, March 2004 came and went without the release. As of the time of my writing, no indication has been given as to when the next edition of ECMAScript will be released. All schedules of record still indicate the Q1 2004 date.
When Netscape submitted its proposal to TC39,the future of Netscape Communications looked bleak. Since that time, Netscape was purchased by Time Warner (then AOL Time Warner) and then summarily disbanded, leaving the future of its Web browser strictly to the open-source Mozilla Foundation. TheMozilla Foundation still supports the Netscape proposal and updates it periodically,although the last update noted was in June 2003.
Netscape’s proposal for ECMAScript would turn ECMAScript into a lightweight version of the Java programming language. The goals listed in the proposal are the following:
Although these goals seem pretty ambitious,the proposal is quick to point out that its authors do not see ECMAScript as a replacement for C++ or Java, nor do they intend to push it in that direction.
In order to accomplish the goals listed previously, the Netscape proposal suggests a number of changes to the language from the third edition.These changes include:
Keywords and reserved words
Netscape proposes the following keywords:
You will probably recognize some of these keywords as reserved words in ECMAScript Edition 3,which is why they are reserved.
Additionally,the proposal asks for the following reserved words:
abstract debugger enum goto implements interface native protected synchronized throws transient volatile
As you can see, this list of reserved words clearly shows the Netscape proposal moving ECMAScript more towards a Java-like syntax.
The following words were reserved in ECMAScript Edition 3, but are used as part of the language in Netscape’s proposal:
boolean byte char double final float int long short static
Finally,special meanings are attached to the words get and set, which cannot be used as variable names.
According to the Netscape proposal,variables can be defined with an explicit type by including a semicolon and the type name when defining the variable, like this:var color : String = “red”;
In the previous code,a variable with name color is created as type String.Defining the type for a variable is optional under this proposal. This can also be used with classes you would define yourself:var specialObject : MyClass = new MyClass();
A slight twist on variables is the capability to create true constant values that cannot be changed by using the const keyword:const age = 32;
This code defines the variable age as a constant and assigns a value of 32.
Functions also take advantage of this new type declaration by providing types for its arguments and return value. Consider the following example:
Here, the function named sum() takes two parameters of type Integer and returns an Integer (as indicated by the semicolon after the closing parenthesis). If the function doesn’t return a value, it is defined as type Void:
Functions that have argument and return value types defined are type checked, although it is possible to leave off the types and have functions behave as they do in ECMAScript today.
Netscape’s proposal would make overloading of functions work in a manner similar to overloading in Java: Just define as many functions as necessary with different argument lists. For example, you could make two different versions of the sum() function defined earlier, one to take two arguments and one to take three:
Another change to functions is the capability to define named arguments,which are optional and can be assigned in any order so long as the name of the argument is used. For example, the following function contains two named arguments:
To call this function, you can use only two arguments, three arguments, or all four:
Note the last two lines where the named arguments are used; specifically notice the last line, where num4 is used before num3.
In order to support more types of numbers, the Netscape proposal introduces three new types of numbers: long, unsigned long (ulong), and float. You can indicate the type of number by including an l (or L) for long values, ul (or uL, Ul, UL) for ulong values, and f (or F) for float values. For example, L25 is a long, UL25 is a ulong, and F25 is a float.
Netscape’s proposal introduces several new types:
Unlike ECMAScript Edition 3, all types are considered objects and not primitive values.
New machine types represent primitive number values:
The machine types can be used in place of regular types whenever a number must be represented.For example:
A class in ECMAScript Edition 4 (per the Netscape proposal) takes a form like this:
As you can see, the class keyword is used to define MyClass. There is one private variable named color, one constructor, and one public method named sayColor().In ECMAScript Edition 4, both public and private are considered namespaces that define the context in which variables and methods can be accessed.Classes defined in this manner are instantiated in the same way as in ECMAScript Edition 3, by using the new keyword:var myObject : MyClass = new MyClass();
Along with variables and methods, it is possible to define getters and setters for properties. The getter is called when the variable is used for the value it contains, whereas a setter assigns a new value to a given variable.
The previous code creates a property named myColor, which can be used just like a regular property (such as color),but whose behavior is defined by the getter and setter functions. For instance:
Typically, this would be done when you want to perform some other action after a property value changes (such as changing the color of a UI element when the myColor property changes). It is also possible to redefine the behavior of operators when they interact with classes.In ECMAScript Edition 3, all operators use an object’s valueOf() or toString() method, but here it is possible for you to define exactly how a plus or minus should be used with an instance of a particular class.
This class defines a private property named value, which can be initialized using the class constructor. The last function defines what happens when a plus is used with a MyClass object. This particular function defines the behavior when the second operand is also a MyClass object: The values of the two objects are added and a new MyClass object is returned. With this definition, it is possible to use the following line:
Finally, classes can have true static properties and methods by using the static keyword:
The static members of a class can then be accessed as you might expect:var value : Integer = MyClass.value;
Inheritance in ECMAScript Edition 4 is done in the same way as in Java, by using the extends keyword. For example:
First,note that the extends keyword is used to inherit from ClassA to create ClassB. This is a much simpler and straightforward way to establish inheritance than the traditional ECMAScript method (although object masquerading and prototype chaining is still available for backwards compatibility). The second thing to note is the use of the super() method to use ClassA’s constructor in ClassB. Once again, this is identical to Java.
Although ECMAScript Edition 4 isn’t an officially released standard,that hasn’t stopped both Microsoft and Mozilla from implementing some of it.
Mozilla chose to implement some small features in the Web browser. For instance,it is possible to define constant values in Mozilla using the const keyword:const message = “Hello World!”;
This line causes an error in all other browsers because const is a reserved word in ECMAScript Edition 3. In Mozilla, however, this line defines a constant string named message that cannot have its value changed.
Mozilla also chose to implement getters and setters for object properties, albeit with a different syntax. You may remember getters and setters from earlier chapters of this book, but here is a brief example:
This is an alternate syntax (so as not to break syntax in non-Mozilla browsers):
Note that even though this example is syntactically correct, it causes an error in browsers other than Mozilla when it is executed because neither function (defineGetter() or defineSetter())is defined.
Java Script Related Tutorials
|Adv Java Tutorial||Core Java Tutorial|
|Java-Springs Tutorial||Java Servlets Tutorial|
|EJB(Enterprise JavaBeans) Tutorial||JavaServer Faces (JSF) Tutorial|
|Java Swing Tutorial||Java Tutorial|
|JavaMail API Tutorial||Java 8 Tutorial|
|Java XML Tutorial||Java Bean Utils Tutorial|
|The Java Debugger (JDB) Tutorial||Java.math Package Tutorial|
Java Script Related Interview Questions
|Java Script Interview Questions||Adv Java Interview Questions|
|Core Java Interview Questions||Java-Springs Interview Questions|
|Java Servlets Interview Questions||EJB(Enterprise JavaBeans) Interview Questions|
|JavaServer Faces (JSF) Interview Questions||Java Swing Interview Questions|
|Java 8 Interview Questions||Java XML Interview Questions|
|JavaFX Interview Questions||The Java Debugger (JDB) Interview Questions|
Java Script Related Practice Tests
|Java Script Practice Tests||Adv Java Practice Tests|
|Core Java Practice Tests||Java-Springs Practice Tests|
|Java Servlets Practice Tests||EJB(Enterprise JavaBeans) Practice Tests|
|JavaServer Faces (JSF) Practice Tests||Java 8 Practice Tests|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.