Web hosting provider - Strings, Math, andDatesFor most of the lessons in
Tuesday, July 31st, 2007Strings, Math, andDatesFor most of the lessons in the tutorial so far, the objects at the cen- ter of attention belong to the document object model. But as indi- cated in Chapter 2, a clear dividing line exists between the documentobject model and the JavaScript language. The language has some ofits own objects that are independent of the document object model. These objects are defined such that if a vendor wished to implementJavaScript as the programming language for an entirely different kindof product, the language would still use these core facilities for han- dling text, advanced math (beyond simple arithmetic), and dates. You can find formal specifications of these objects in the ECMA-262recommendation. Core Language ObjectsIt is often difficult for newcomers to programming or even experi- enced programmers who have not worked in object-oriented worldsbefore to think about objects, especially when attributed to things that don t seem to have a physical presence. For example, itdoesn t require lengthy study to grasp the notion that a button on apage is an object. It has several physical properties that make perfectsense. But what about a string of characters? As you learn in thischapter, in an object-based environment such as JavaScript, every- thing that moves is treated as an object each piece of data from aBoolean value to a date. Each such object probably has one or moreproperties that help define the content; such an object may also havemethods associated with it to define what the object can do or whatyou can do to the object. I call all objects that are not part of the document object model corelanguage objects. You can see the full complement of them in theQuick Reference in Appendix A. In this chapter, I focus on the String, Math, and Dateobjects. String ObjectsYou have already used Stringobjects many times in earlier lessons. A stringis any text inside a quote pair. A quote pair consists of eitherdouble quotes or single quotes. This allows one string to nest inside1010CHAPTER …In This ChapterHow to modify stringswith common stringmethodsWhen and how to usethe MathobjectHow to use the Dateobject …