Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
03/24/2008
Times viewed :
380
JavaScript Objects
Introduction
JavaScript supports built in objects like the Math, String
or Date object. All these objects provide some functions, which can be called
for some processing. However you can also create your own objects. Usually
objects are declared with the keyword new.
Get and set an Object property
You can get and set the object property in two ways. Either
with objName.PropertyName or objName[“PropertyName”]. Both will result to the
same value.
Deleting an object property
You can delete an object property with the keyword delete.
Once the property has been deleted, it will be defined as undefined.
Example
In the following example I have declared a function called
Building. The function contains several properties, which defines the building.
As you can see you set these properties inside the function with the keyword
this. Once you have created the object, you can set a new value for these
properties, with the object name and the property name.
<html>
<head>
<script type="text/javascript">
function
Building()
{
this.type
= "6 Plex"
this.constructionYear
= "2003"
this.value
= "300.000 USD$"
}
var
objBuilding = new Building()
document.write("The
building rate in year "+ objBuilding.constructionYear)