first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

JavaScript: Using Constructor Functions to Create User-Defined Objects

Using constructor functions to create user-defined objects is the "old" but respectable---and backward-compatible way of getting the job done. Building the constructor function is the first step in creating the user-defined object. This creation has the form:

function myConstruct(arg1, arg2, arg3) {

    //Properties:
    this.property1 = arg1
    this.property2 = arg2
    this.property3 = arg3

    //Methods:
    this.method1 = myFunc1
    this.method2 = myFunc2
    this.method3 = myFunc3
}

The instantiation is the second and final step; it has the form:

objUser = new myConstruct

such that objUser.property2 will return the value of arg2 immediately after the instantiation.

The "new" way to create user-defined objects is via what Netscape calls "object initializers" for their 4.0-class browsers (JavaScript 1.2). This creation has the form:

objectName = {property1:value1, property2:value2,..., propertyN:valueN}

More information on both ways of doing things may be found at developer.netscape.com with path:

/docs/manuals/js/client/jsguide/obj.htm
mod date: 2001-10-29T01:56:19.000Z