Difference between revisions of "JavaScript Object Basics"

From Techotopia
Jump to: navigation, search
Line 1: Line 1:
JavaScript Objects represent self contained entities consisting of properties and functions (called methods in object terminology) that can be used to perform tasks and store complex data. JavaScript objects fall into three categories - Built-in Objects, Custom Objects and Document Object Model (DOM) Objects.
+
JavaScript Objects represent self contained entities consisting of variables (called ''properties'' in object terminology) and functions (called ''methods'') that can be used to perform tasks and store complex data. JavaScript objects fall into three categories - Built-in Objects, Custom Objects and Document Object Model (DOM) Objects.
  
 
Built-in objects are objects that are provided with JavaScript to make your life as a JavaScript developer easier. In many of the examples given in this book we have used the document.write() mechanism to write text to the current web page. Whether you knew it or not, you have been using the write() method of the JavaScript built-in document ''object'' when you have run these scripts.
 
Built-in objects are objects that are provided with JavaScript to make your life as a JavaScript developer easier. In many of the examples given in this book we have used the document.write() mechanism to write text to the current web page. Whether you knew it or not, you have been using the write() method of the JavaScript built-in document ''object'' when you have run these scripts.

Revision as of 14:43, 25 April 2007

JavaScript Objects represent self contained entities consisting of variables (called properties in object terminology) and functions (called methods) that can be used to perform tasks and store complex data. JavaScript objects fall into three categories - Built-in Objects, Custom Objects and Document Object Model (DOM) Objects.

Built-in objects are objects that are provided with JavaScript to make your life as a JavaScript developer easier. In many of the examples given in this book we have used the document.write() mechanism to write text to the current web page. Whether you knew it or not, you have been using the write() method of the JavaScript built-in document object when you have run these scripts.

Document Object Model (DOM) Objects provide the foundation for creating dynamic web pages. The DOM provides the ability for a JavaScript script to access, manipulate, and extend the content of a web page dynamically (i.e without having to reload the page). The DOM essentially presents the web page as a tree hierarchy of objects representing the contents and elements of the web page. These objects, in turn, contain properties and methods which allow you to access and change parts of the web page.

Custom objects are objects that you, as a JavaScript developer, create and use. Creating a custom object is possibly the best way to fully understand what objects are, so in this chapter we will by looking at how to create custom objects before covering the Built-in and DOM Objects in later chapters.