Creating a Class


function UniversalClass() { } 

There is no distinctive keyword for classes in JavaScript. Instead, each class is defined as a function. The difference between a regular function and this one is the way this function is later called: with the new keyword. The following listing implements a simple class; upon instantiation, the window.alert() box pops up.

A Simple Class (class.html)

<script language="JavaScript"   type="text/javascript"> function UniversalClass() {   window.alert("Welcome to my class!"); } var uc = new UniversalClass(); </script> 




JavaScript Phrasebook(c) Essential Code and Commands
JavaScript Phrasebook
ISBN: 0672328801
EAN: 2147483647
Year: 2006
Pages: 178

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