Object-Oriented Programming With Javascript Syntax - MACROMEDIA DIRECTOR MX 2004-DIRECTOR SCRIPTING Reference

Director scripting reference
Table of Contents

Advertisement

In general, keep the following in mind:
When using a reference to a script instance as a target, the target handler in that particular
script instance is called. This technique does now allow the use of custom properties.
When using a reference to anything other than a script instance (such as a property list) as a
target, the target handler in a movie script is called. This technique allows the use of custom
properties.

Object-oriented programming with JavaScript syntax

Object-oriented programming in JavaScript syntax is somewhat different than it is in other
object-oriented languages such as Java and C++—while some object-oriented languages are class-
based, JavaScript syntax is prototype-based.
The following two bullet points compare and contrast, at a high level, class-based languages with
prototype-based languages such as JavaScript syntax.
In class-based languages, you create class definitions that define the initial properties and
methods that characterize all instances created from those classes. A class definition contains
special methods, called constructor methods, that are used to create the instances of that class.
When an instance is created by using the
constructor method, that instance inherits all the properties of its parent class. That instance
can also perform other processing specific to that instance depending on the constructor that
was called.
In a class definition, you perform inheritance by creating a subclass that inherits all the
properties of its parent class, in addition to defining new properties and optionally modifying
inherited ones. The parent class from which a subclass is created is also known as a super-class.
In prototype-based languages, such as JavaScript syntax, there is no distinction between classes,
instances, subclasses, and so on—they are all known as objects. Instead of using class
definitions, in JavaScript syntax you use "prototype objects" as the template from which new
objects are created. Similar to class-based languages, in JavaScript syntax, you create a new
object by using the
Instead of using super-classes and subclasses, in JavaScript syntax, you associate prototype
objects with constructor functions to perform inheritance. This process is very similar to using
super-classes and subclasses, only with different terminology.
Also, as opposed to class-based languages, in JavaScript syntax you can add and remove
properties from an object or set of objects at runtime. For example, if you add a property to a
prototype object at runtime, any instance objects for which it is a prototype also get that
property.
Object-oriented terminology
Because all types in JavaScript syntax are known as objects, class-based terms such as super-class,
subclass, class, instance, and so on do not have literal technical meanings in JavaScript syntax.
However, all of these terms essentially map to objects in JavaScript syntax, and are convenient to
use generically when referring to the different types of JavaScript syntax objects. Therefore, these
class-based terms are used interchangeably with object throughout the discussion about object-
oriented programming in JavaScript syntax to mean the following:
superclass Any class from which subclasses (objects) are created; a parent class.
subclass Any class that has been created from a superclass (object); a child class.
operator in association with a constructor function.
new
Object-oriented programming with JavaScript syntax
operator in association with a particular
new
65

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Director mx 2004

Table of Contents