Click to return to the Component Development home page    
Welcome to Scriptlet Tech...    
Web Workshop  |  Component Development

Creating a public_description Object


A public_description object is a JScript® (compatible with ECMA 262 language specification) object that provides run time 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 more information, 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 to 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(){
   return (window.document.title == "" ? "This document has no title" : 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



Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.