Server-Side JScript Objects, Part 2
By Richard Lowe
In Part 1 we looked at the createTicket() function for our
Ticket object. In this part we will look at how to tie the createTicket() function
into the Ticket object by using an object constructor.
The Object Constructor
The next step is to define the JavaScript object with an object constructor. An object constructor is a
simply a JavaScript function with a specific syntax that is used to define the elements of an object. It
looks like this:
|
This syntax can then be applied to the ticket object for the helpdesk project:
|
The object is now available to ASP using JScript, however most developers will want to continue using VBScript as their primary ASP language. This creates another step in the process, returning an object to VBScript with one more small function:
|
The partially completed ticket object is now ready to be used in VBScript. It is easiest to place objects
into #include files on their own, so that the includes on a particular page are as finely granular
as possible.
|
Note, the above script uses with With block, requiring VBScript 5.0 or greater. To learn more
about the With block be sure to read: Using the With Block.
To determine your VBScript version be sure to read: Determining the Server-Side
Scripting Language and Version.
Implementing JScript objects in a VBScript-driven ASP page takes some planning and patience. However a properly
implemented set of JScript objects in finely granular #include files can significantly reduce the
cycle time in most sizes of ASP-based project because they:
- Provide functionality that can be re-used by any developer who's ever used COM objects in ASP.
- Allows script-only programmers to use object design prinicples in their ASP application.
- Place functions and properties into logical, easy to use groupings.
Happy Programming!
Richard Lowe (chadich@yahoo.com)
Richard Lowe works as a Development Services consultant for Spherion in the
Technology Group
Attachments:
objTicket.asp in text format



