What is this site?

HTML5Labs is where Microsoft prototypes early and unstable
specifications from web standards bodies such as W3C. Sharing these
prototypes helps us have informed discussions with developer
communities, and enables us to provide better feedback on draft
specifications based on this implementation experience. To find out
more about HTML5Labs, read the
blog by Jean Paoli, President, Microsoft Open
Technologies, Inc.

JavaScript Extensions

As the HTML5 platform becomes more fully
featured, web applications become richer, and scenarios that
require server side interaction for trivial tasks become more
tedious. This makes deficits in the capabilities of JavaScript as a
runtime come into focus.

Microsoft is committed to advancing the
JavaScript standard. Through active participation in the EcmaTC39
working group, we have endorsed and pushed for the completion of
proposed standards which provide extensions to the intrinsic
Math,
Number, and
String libraries and introduce support for
Globalization. We shared the first version of prototypes for
the libraries at the standards meeting on the Microsoft campus in
July and are shared our Globalization implementation at the
standards meeting last week at Apple's Cupertino campus. In
addition, we are also releasing these reference implementations so
that the JavaScript community can provide feedback on applying
their use in practice.

What's in this drop

This drop includes extensions to the Math,
Number, and String built-in libraries:

Math

String

Number

cosh, sinh, tanh

startsWith, endsWith

isFinite

acosh, asinh, atanh

contains

isNaN

log1p, log2, log10

Repeat

isInteger

sign

toArray

toInteger

trunc

reverse

To illustrate, a simple code sample using some
of these functions is included below:

varaStr ="24-";

varaStrR =
aStr.reverse();

varnum = aStrR *1;

if(Number.isInteger(num))
{

console.log("The sign of
"+ num +" is "+
Math.sign(num));

};

This drop also includes an implementation of
the evolving Globalization specification. Globalization is the
software discipline that makes sure that applications can deal
correctly with changes in number and date formats, for example.
It's a part of the localization of an application to run in a local
language. With this library, you can show date and numbers in the
specified locale and specify collation properties for the purposes
of sorting and searching in other languages. You can also set
standard date and number formats to use alternate calendars like
the Islamic calendar or formats to show currency as a Chinese Yuan.
Again, a code sample illustrates below:

varnf =newGlobalization.NumberFormat(localeList,
{

style :"currency",

currency :"CNY",

currencyDisplay:"symbol",

maxmimumFractionDigit:1

})

nf.format(100);//
"¥100.00"

vardtf =newGlobalization.DateTimeFormat(

newGlobalization.LocaleList(["ar-SA-u-ca-islamic-nu-latin"]), {

weekday :"long",

})

dtf.format()// today's
date

dtf.format(newDate("11/15/2011"));// "الثلاثاء,١٢١٩٣٢"

How to get the bits

Note that as with all previous releases of
HTML5 labs, this is an unsupported component with an indefinite
lifetime. This should be used for evaluation purposes only and
should not be used for production level applications.

Providing Feedback

We've created a couple of sample applications
so you can see what this functionality enables. Once you've
installed the bits, view the
Intrinsics Extensions demo and the
Globalization demo to see the APIs in action.

As usual, we encourage you to play with the
sample apps, download the prototype, and develop your own app to
see how it feels. Once you've tried it out, let us know if you have
any feedback or suggestions. We look forward to improving
JavaScript and making it ever easier to build great web
applications using standard APIs.