Chapter 23. Cookies and Creating Your Own Objects


graphics/chic01.gif

In this chapter, we'll take a look at two topics near and dear to the JavaScript programmer's heart: using cookies and creating your own objects.

Everyone knows about cookies they're those data items that you can store on someone's computer. You can store everything from the users' name (if they give it to you) to the current items they've purchased and how much their total is. Using cookies is easier than you might think in JavaScript, and we'll take a look at how to work with them in this chapter. We'll see not only how to create and store a cookie, but also what's involved in reading them at a later time. We'll also see how to specify when a cookie expiresthat is, when the browser should delete it. And we'll see how to delete a cookie ourselves .

We'll also take a look at creating custom objects in this chapter. JavaScript uses objects, but it's not truly object-oriented, because it doesn't support all those elements that are necessary for true object-oriented programming (OOP), such as classes, inheritance, polymorphism, and more.

Instead, some people consider JavaScript object-based . That is, instead of supporting all the OOP formality , JavaScript enables you to work with many preexisting objects, such as the built-in objects such as String , Array , Boolean , and so on, as well as gives you access to browser objects such as the document , navigator , and window objects.

Nonetheless, you can create your own objects in JavaScript, and we'll see how to do so here. We'll create new objects that support not only properties, but methods as well. We'll even see how to create constructors to which you can pass data to initialize your objects.

That's the program for this chapter thenworking with cookies and custom objects. These are both favorite topics for the JavaScript programmer, and we'll get all the details in this chapter.



Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net