Object-oriented programming with JavaScript syntax
65
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
new
operator in association with a particular
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
new
operator in association with a constructor function.
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.
Содержание DIRECTOR MX 2004-DIRECTOR SCRIPTING
Страница 1: ...DIRECTOR MX 2004 Director Scripting Reference...
Страница 48: ...48 Chapter 2 Director Scripting Essentials...
Страница 100: ...100 Chapter 4 Debugging Scripts in Director...
Страница 118: ...118 Chapter 5 Director Core Objects...
Страница 594: ...594 Chapter 12 Methods...
Страница 684: ...684 Chapter 14 Properties See also DVD...
Страница 702: ...702 Chapter 14 Properties See also face vertices vertices flat...
Страница 856: ...856 Chapter 14 Properties JavaScript syntax sprite 15 member member 3 4...
Страница 889: ...netPresent 889 _player alert Sorry the Network Support Xtras could not be found See also Player...
Страница 1102: ...1102 Chapter 14 Properties...