Search results for 'Object'. 1 post(s) found.

  1. 2007/08/26 Example Of Creating Objects
2007/08/26 21:13

Example Of Creating Objects


an example of creating Object in javascript,
taken from http://www.wdvl.com/Authoring/JavaScript/Tutorial/Objects.html

direct instance of an Object

Despite the awkward sound name, a "direct instance of an Object" simply means creating a new single Object, such as myPetDog:


myPetDog=new Object();
 myPetDog.name="Barney";
 myPetDog.breed="beagle";
 myPetDog.year=1981;

 

Assigning a method to your new Object is also simple. Assume that you already have coded a function named woof(), which causes a barking sound to play:


myPetDog.woof=woof;

 

prototype of an Object
Sometimes, you'll want to create a "template" or prototype of an Object. This does not create an actual instance of the Object, but defines the structure of the Object. In the future, then, you can quickly stamp out a particular instance of the Object. Suppose that instead of myPetDog, you created a prototype Object named petDog. This Object could then be a template for a particular pet dog Object. First, create a function which defines the petDog structure:

function petDog(name, breed, year)
{
  this.name = name;
  this.breed = breed;
  this.year = year;
}

 

Now that the petDog prototype has been set, you can quickly create single instances of a new Object based on the petDog structure:


myPetDog=new petDog("barney","beagle",1981);
yourPetDog=new petDog("max","terrier",1990);

Trackback 6 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject Cialis viagra levitra.

    Tracked from About glaxosmithkline pharmaceuticals and levitra. 2009/05/24 14:09 delete

    How does levitra work. Comparison levitra cialis. Levitra.

  2. Subject Buy levitra online.

    Tracked from Levitra. 2009/05/30 11:31 delete

    Levitra dosage. Levitra side effects. Levitra attorneys. Cialis viagra levitra. Cheapest generic levitra. Levitra.

  3. Subject Vicodin.

    Tracked from Vicodin consultation. 2009/07/26 04:03 delete

    Signs of vicodin addictio.

  4. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 03:57 delete

    moneyideas

  5. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 12:55 delete

    moneyideas

  6. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:43 delete

    moneyideas