Jump to content

Recommended Posts

  • FPCH Admin
Posted

Up to this point we have mostly talked about improved JavaScript performance in Internet Explorer 9 but we haven&rsquot said much about any new or changed language features in the &ldquoChakra&rdquo engine. Now, with the third Platform Preview, we can tell you about JavaScript feature enhancements which you can try for yourself.

 

 

As context, the industry standard that defines the JavaScript language is ECMA-262: ECMAScript Language Specification developed and published by Ecma International. Prior to last year, it had been a decade since the introduction of the Third Edition of ECMA-262 in December 1999. In December 2009 Ecma approved the Fifth Edition of ECMA-262 as the successor to the Third Edition (a Fourth Edition was never published), and last year we debuted elements of ECMAscript 5 (ES5) support when we added native JSON support in IE8. Beyond JSON, though, ES5 standardizes many significant enhancements to the JavaScript language.

New ES5 Features in the IE9 Platform Preview

 

 

There are many important ES5 features implemented in IE9 Standards Document mode:

 

 

New Array Methods. There are nine new methods that operate upon arrays. Two of them, indexOf and lastIndexOf, support searching an array for a particular value. They are similar in concept to the functions with the same names that operate upon strings. The other seven new Array methods allow arrays to be manipulated using a functional programming style. For example, the following snippet uses the new filter method to collect the elements of an array that meet a specific condition:

 

 

 

//a function that tests whether menu item object is enabled or disabled

function enabled(menuItem) {return menuItem.status==="enabled"}

 

 

//Assume that individual menu items have a status property and

//that a menu object has a items property which is an array.

//Create an new array containing just the enabled menu items

var enabledItems=myMenu.items.filter(enabled)

 

 

 

These methods support various forms of array processing without having to explicitly code for loops. In addition, they are all generic, which means that they can be applied to any object with numerically indexed properties and not just objects created using the Array constructor. You can explore demos using these methods on the IE9 Test Drive site and they are summarized in the following table:

 

 

 

 

 

 

Array method

 

 

 

 

Description

 

 

 

 

 

 

indexOf

 

 

 

 

Search an array for the first occurrence of some value

 

 

 

 

 

 

lastIndexOf

 

 

 

 

Search an array for the last occurrence of some value

 

 

 

 

 

 

forEach

 

 

 

 

Apply a function to each element of an array

 

 

 

 

 

 

every

 

 

 

 

Determine if some condition is true for every element of an array

 

 

 

 

 

 

some

 

 

 

 

Determine if some condition is true for at least one element of an array

 

 

 

 

 

 

map

 

 

 

 

Apply a function to each element of an array and produce a new array containing the results

 

 

 

 

 

 

filter

 

 

 

 

Collect into a new array all the elements of an array for which some condition is true.

 

 

 

 

 

 

reduce

 

 

 

 

Accumulate a single value based upon all elements of an array.

 

 

 

 

 

 

reduceRight

 

 

 

 

Accumulate a single value based upon all elements of an array, processing them in reverse order.

 

 

 

 

 

 

Enhanced Object Model. The most important new feature in this area is accessor properties. These are also sometimes called &ldquogetter/setter&rdquo properties because they allow JavaScript programmers to control what happens when the program gets or sets the property value. ES5&rsquos enhanced object model also allows programmers to control whether individual properties can have their value changed, are enumerated by for-in statements, and whether or not the property can be deleted or redefined. It also allows the programmer to control whether new properties can be added to an object. ES5 also enables JavaScript programmers to more easily create objects that inherit from specific prototype object and to inspect and manipulate the property definitions of object. All of these enhanced object model capabilities are accessible via new function properties of the Object constructor. However, note that the current release of the IE9 platform preview does not yet fully support use of these methods with DOM objects.

 

 

 

 

 

 

Object function

 

 

 

 

Description

 

 

 

 

 

 

Object.defineProperty

 

 

 

 

Create or modify a property definition. The property can be defined as either a data or an accessor property and its writable, enumerable, and configurable property attributes can be set.

 

 

 

 

 

 

Object.defineProperties

 

 

 

 

Create or modify multiple property definitions in a single operation.

 

 

 

 

 

 

Object.create

 

 

 

 

Create a new object with a specified prototype and optionally a set of specified properties.

 

 

 

 

 

 

Object.getPrototypeOf

 

 

 

 

Retrieve the prototype object of the argument object.

 

 

 

 

 

 

Object.getOwnPropertyDescriptor

 

 

 

 

Return a complete description of the attributes of a property of an object.

 

 

 

 

 

 

Object.getOwnPropertyDescriptor

 

 

 

 

Return an array containing the names of all of an object&rsquos non-inherited properties.

 

 

 

 

 

 

Object.keys

 

 

 

 

Return an array containing the names of all of an object&rsquos non-inherited properties that would be iterated by the for-in statement.

 

 

 

 

 

 

Object.seal

 

 

 

 

Disallow adding any additional properties to the argument object and disallow deletion or redefinition of any existing properties. Individual property values may still be modified if their writable attribute have the value true.

 

 

 

 

 

 

Object.freeze

 

 

 

 

Disallow adding any additional properties to the argument object and disallow deletion or redefinition of any existing properties. In addition the values of existing property may not be modified.

 

 

 

 

 

 

Object.isSealed

 

 

 

 

Test whether an object is has been sealed using Object.seal.

 

 

 

 

 

 

Object.isFrozen

 

 

 

 

Test whether an object is has been frozen using Object.freeze.

 

 

 

 

 

 

Object.preventExtensions

 

 

 

 

Disallow adding any additional properties to an object.

 

 

 

 

 

 

Object.isExtensible

 

 

 

 

Test whether new properties may be added to an object.

 

 

 

 

 

 

Other Computational Methods and Functions. In addition to the new Array and Object methods, ES5 adds or enhances several additional methods that perform useful computational operations.

 

 

 

 

 

 

Method or Function

 

 

 

 

Description

 

 

 

 

 

 

String trim

 

 

 

 

Removes &ldquowhite space&rdquo from the beginning and end of a string.

 

 

 

 

 

 

Date toISOString

 

 

 

 

Convert a Date to a string format that all ES5 implementations must support.

 

 

 

 

 

 

Date.parse

 

 

 

 

Existing function enhance to recognize the format create by toISOString.

 

 

 

 

 

 

Date.now

 

 

 

 

Return a numeric timestamp

 

 

 

 

 

 

Array.isArray

 

 

 

 

Reliably test whether an object is an Array

 

 

 

 

 

 

Function bind

 

 

 

 

Preset some of the arguments of a function to fixed values.

 

 

 

 

 

 

ES5 also includes a number of other minor changes and technical corrections to the language. Many have no impact on most JavaScript programmers because they simply standardize minor features that have always been supported by browsers. An example of such a feature is line continuations within string literals. One minor change is of more interest. Reserved names such as if, super, and public can now be used as property names within object literals and for property access following a dot. With this change, programmers no longer need to worry about a long and arbitrary list of words that they can&rsquot easily use as property names.

 

 

&ldquoSame Script, Same Markup&rdquo

 

 

Updating IE9&rsquos JavaScript implementation isn&rsquot just about supporting new ES5 features. It&rsquos also about ensuring that web developers can use the same markup and script within IE9 that they use in other browsers. Earlier this year we released documents that describe in detail how JavaScript as implemented in IE8 differs from the ECMAScript, Third Edition Specification. In IE9 standards mode, we looked closely at these differences and made changes to ensure that IE9 can execute the same script as other browsers.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...