كود PHP:

    
Script 
Function Objects
'Script' function object is an object with properties and functions created entirely by the scriptThe objects can have many functions and hold any script objects as propertiesboth the functions and the properties are defined by the script developerThese objects are most commonly created by Library or Fragment files so that they are self contained and easily reused.

Creating an Instance
To create an instance of a Script 
function object the keyword "new" is used just as it is for all other objectsThe new statement is followed by the name of the type of object wantedThis name refers to a function that is used to construct the Script objectThis function is called the 'Constructor' function. The example below shows the creation of a new 'car' Script object:

function 
car(makemodelyear) {
  
this.make make;
  
this.year year;
  
this.model model;
}

myVw = new car("VW""Golf gti"1991);

This example creates a new Script function object called myVwNote that the keyword "this" has been introduced"this" refers to the current instance of the Script object (in this case the new one we are creating). So the reference 'this.make' means access the property 'make' in the current instance of the Script object defined by the function.

The properties created in the Constructor function are instance properties and are only available in this instance of the Script object. If another instance of the Script object is created then it will have its own version of these propertiesThese properties can be accessed from outside the function in the same way as all object properties are accessed.

e.g.

make myVw.make;

The Constructor function that is used to create the Script function object can contain more than just propertiesit can also contain references to other functionsThese functions then become the functions available as part of the script objectThe example below shows the car function extended to include a getCarMake() function.

function 
car(makemodelyear) {
  
this.make make;
  
this.year year;
  
this.model model;
  
this.getMake getCarMake;
}

function 
getCarMake() {
  return 
this.make;
}

myVw = new car("VW""Golf gti"1991);
make myVw.getMake();

The addition of the line 'this.getMake = getCarMake;' in the Constructor function creates a function reference to the getCarMake() function that becomes an object "function"Note that the name of the function reference does not need to be the same as the name of the function.

 
Shared Properties
Shared properties are properties that are accessible by all instances of the same Script 
function object within the current pageShared properties are only available inside the current page and will be lost when the current page finishes execution even if the Script function object is persisted beyond the current page by putting it in the project object.

There is only one instance of a shared properties and when this is changed in one Script object its new value is available in all other instances of the same Script object.

Shared properties are created by the special reference 'prototype'.

e.g.

car.prototype.date = new Date();

myVw.prototype.date = new Date();

this.prototype.date Date();

The first example creates a shared date property for the 'car' Script objectThe second example creates a shared date property for the 'car' Script object using a reference to a previously created instance of the Script objectThe third example creates a shared date property from within a Script object function. After any of these examples any other instances of 'car' Script objects created before or after the example will have the shared 'date' property available