Properties and Methods
Every objrcts has it's own propeties and methods.
- Properties define the characteristics of an object.
Examples : color, lenght, name, height, width
- Methods are the actions that the object can perform or that can be performed on the object.
Examples : alert, confirm, write, open, close
Naming Objects
- Objects are organized in a hierarchy. To refer to an object use :
objectName
- To refer to a property of an object use :
objectName.propertyName
- To refer a method of an object use :
objectName.methodName()
Build-In Objects
Some of the built-in language objects of JavaScript offer more advanced operations such as :
- Math - provides for math calculation
- Date - provides date and time information
- String - provides for string manipulation
Math Object
The Math object provides methods for many mathematical calculations, including : abs(), pow(), random(), round(), sqrt().
format : Math.method(#)
Math Example
- keep the "userdefined.html" file open
- Put the cursor in the BODY section and enter :
<SCRIPT language="JavaScript"> var theNumber=3.14 myNum=Math.round(theNumber) </SCRIPT>
- Save the changes and Refresh the page
The Date object provides the day, date, and time information.
Format : dateObject.method()
Date Example
- Keep the "userdefined.html" file open
- Pit the cursor in the BODY section and enter :
<SCRIPT language="JavaScript"> var rightNow=new Date() theYear=rightNow.getFullYear() </SCRIPT>
- Save the changes and Refresh the page
String Object
The String object provides methods and properties for tring manipulation and formatting.
Format : stringName.method()
String Example
- Keep the "userdefined.html" file open
- Put the cursor after the Date example and enter :
<SCRIPT language="JavaScript"> var theString="my name" varPrintString=theString.bold() varnumChars=theString.length </SCRIPT>
- Save the changes and Refresh the page
0 komentar:
Post a Comment