 |
|
 |
|
 |
 |
|
|
|
|
|
|
Programmers familiar with object-oriented programming (OOP) in Java or C++ may think of
objects as modules that contain two kinds of members: data stored in member variables or
properties, and behavior accessible through methods. The ECMAScript edition 4 draft, the
standard upon which ActionScript 3.0 is based, defines objects in a similar but slightly
different way. In the ECMAScript draft, objects are simply collections of properties. These
properties are containers that can hold not only data, but also functions or other objects. If a function is attached to an object in this way, it is called a method.
While the ECMAScript draft definition may seem a little odd to programmers with a Java or C++ background, in practice, defining object types with ActionScript 3.0 classes is very similar to the way classes are defined in Java or C++. The distinction between the two definitions of object is important when discussing the ActionScript object model and other advanced topics, but in most other situations the term properties means class member variables as opposed to methods. The Flex 2 Language Reference, for example, uses the term properties to mean variables or getter-setter properties. It uses the term methods to mean functions that arepart of a class.
One subtle difference between classes in ActionScript and classes in Java or C++ is that in ActionScript, classes are not just abstract entities. ActionScript classes are represented by class objects that store the class’s properties and methods. This allows for techniques that may seem alien to Java and C++ programmers, such as including statements or executable code at the top level of a class or package.
Another difference between ActionScript classes and Java or C++ classes is that every ActionScript class has something called a prototype object. In previous versions of ActionScript, prototype objects, linked together into prototype chains, served collectively as the foundation of the entire class inheritance hierarchy. In ActionScript 3.0, however, prototype objects play only a small role in the inheritance system. The prototype object can still be useful, however, as an alternative to static properties and methods if you want to share a property and its value among all the instances of a class.
In the past, advanced ActionScript programmers could directly manipulate the prototype
chain with special built-in language elements. Now that the language provides a more mature
implementation of a class-based programming interface, many of these special language
elements, such as __proto__ and __resolve, are no longer part of the language. Moreover,
optimizations of the internal inheritance mechanism that provide significant Flash Player
performance improvements preclude direct access to the inheritance mechanism.
<Flex 2 language Reference 36 page>
actionscript 와 java or c++ 의 class 간의 개념이 약간 다르다.
어찌보면 다아나믹한 움직임을 구현하기 위해선 필요한 차이점인지 모른다.
그래도 ECMAScript 기반의 언어라 그런지 java 와는 외향이 거의 흡사해진다는 느낌이다.
prototype 은 뭔가 꺼림직해서 이전부터 건드리지 않은 부분이지만 아니나 다를까 성능에 문제가 있을 수 있다고 하니 protoype object 는 터치하지 말아야 겠다...
|
|
| 이 글의 관련글(트랙백) 주소 :: http://kimkijeung.com/trackback/55 |
|
|
|
|
|
 |
|
|