Microsoft Scriptlet TechnologyMicrosoft Scriptlet Technology*
*Contents  *Index  *Topic Contents

Creating a Public_Description Object

A Public_Description object is a JavaScript object that provides runtime access to the properties and methods defined by the object's constructor function. A skeleton Public_Description object with its constructor function looks like this:

<SCRIPT LANGUAGE="JavaScript">
   var Public_Description = new CreateScriplet();

   Function CreateScriptlet(){
      // statements here to define properties and methods
   }
</SCRIPT>

Note   You do not use the constructor function to define events. For details, see Defining Event Handlers.

When you create the Public_Description object, the constructor function that you assign to it can have any name, as long as the corresponding function appears somewhere in the scriptlet. Within the constructor function, you declare the properties and methods that you want to expose within the scriptlet in the following ways:

Constructor syntaxCreates
This.PropertyName = expression; Creates a read-write property.
This.get_PropertyName = function;
This.put_PropertyName = function;
Creates a property using a function, which allows you set a property value based on a condition or trigger an event when the property is set. The function called by the property definition can be in any active scripting language. To make a property read-only, do not provide the put_ function declaration; to make it write-only, do not provide the get_ function declaration.
This.method = methodFunction;Creates a method defined by the function methodFunction.

For example, the following Public_Description object defines two properties and a method. The first property, DefaultTitle, is created as an expression. The second property, CalculatedTitle, is created as a set of functions. The method toggleColor is defined using the function TColor.

<SCRIPT LANGUAGE="JavaScript">
// Public_Description object used to declare scriplet
var Public_Description = new ScriptletObject();

// general object description
function ScriptletObject()
{
   this.DefaultTitle = window.document.title;   //property
   this.get_CalculatedTitle = readCTitle;      //property (read)
   this.put_CalculatedTitle = writeCtitle;      //property (write)
   this.ToggleColor = TColor;                     //method
}

// read function for CalculatedTitle property
function readCTitle(){
   if (window.document.title) == ""
      return "This document has no title";
   else
      return window.document.title;
}

// write function for CalculatedTitle property
function writeCTitle(passedValue){
   if !(passedValue) == "" 
      window.document.title = passedValue;
}

// function for ToggleColor method
function TColor(){
   if (window.document.bgcolor) == "#ff0000"{
      // doc is red, make it blue
      window.document.bgcolor = "#0000ff;}
   else{
      // doc is not red, make it red
      window.document.bgcolor = "#ff0000";}
}
</SCRIPT>

See Also

Using Default Interface Descriptions

Handling Standard Events

Defining Custom Events


Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.