article

creating objects using an object constructor function

[what]

  1. [] CREATING-objects-using-a-constructor-function - creating an "object" instance or instances by calling an object Constructor function.
  2. [] A "object" constructor function is a function whose purpose it is, is to create a new instance of a given object.
  3. [] Typically the constructor function will have parameters specified that we can use to pass the object property values into.
  4. [] Sometimes we get those values from user input, or a db qry or a file.
  5. [] So we create an object with property names only and then pass that object "variables" to assign "values" to the properties in the object. 

[why]

  1. [] when we dont know what values the properties of our object will contain when we define/create/declare the object,
  2. [] As we (mostly) need to create objects dynamically, (meaning we don't always know what the values of our objects properties will be when we create the object at design time), having a constructor function enables us to create new object instances when/where we require them.

[where]

  1. []

[when]

  1. [x] 2013-09-03 -
  2. [x] 2019-12-07 - updated

[example]

  1. [] CREATING AN OBJECT CONSTRUCTOR FUNCTION

function Person (id,name,birthdate){
  this.id = id;
  this.name = name;
  this.birthdate = birthdate;

}

  1. ] CREATING an OBJECT INSTANCE using the OBJECT CONSTRUCTOR FUNCTION

var myPerson = new Person(1, "john doe", "2000-01-01");

[how-to]

  1. [] creating a "Person" object constructor function
    1. [] defining the function that will create Person objects.
  2. [] creating an instance of a Person object 
    1. [] once you have created a constructor function, you can now use it to create instances of your objects

[reference]

  1. [x] # 7450 UPDATE-article# 1681 (this) -

 


 


 

Details Photos Edit more

Details

ID: 1681

NAME: 002-CREATING-objects-using-a-constructor-function

DESCRIPTION: 002-CREATING-objects-using-an-object-constructor-function - creating "object" instances by calling an object Constructor function.

AUTHOR: article.author/s

EDITOR: article.editor/s

PUBLISHER: article.publisher/s

STATUS: Write

PRIORITY: -5

OWNER ID: 75

Content Photos Edit more

photos

page_photo

actions

Email Email-Owner SMS and