好的,我在自己的 .AS 文件中创建了这两个类 (foo
和)。bar
这两个类都保存在一个名为custom
.
在我称为“Sandbox”的 .FLA 文件中,我将以下代码放入时间线中:
import custom.foo;
import custom.bar;
var f:foo = new foo("FOO");
var b:bar = new bar("BAR");
trace(f.valueOf());
trace(b.valueOf());
f.statement();
b.statement();
我得到以下输出:
食品
酒吧
声明:值为FOO
声明:值为BAR
现在,通常,我不会想太多,但看看类的代码......这是foo.as
文件(减去我的评论):
package custom {
public class foo {
public var property:String;
public var value:String;
public function foo (par:String = "?") {
this.property = par;
this.value = this.valueOf();
return;
}
prototype.expression = function () {
trace ("Expression: the value is", this.property);
}
public function statement () {
trace ("Statement: the value is", this.property);
}
public function valueOf() {
return(this.property);
}
}
}
...这是bar.as
文件(减去我的评论):
package custom {
public class bar {
public var property:String;
public var value:String;
public function bar (par:String = "?") {
prototype.property = par;
prototype.value = prototype.valueOf();
return;
}
prototype.expression = function () {
trace ("Expression: the value is", prototype.property);
}
public function statement () {
trace ("Statement: the value is", prototype.property);
}
public function valueOf() {
return(prototype.property);
}
}
}
为什么我使用prototype
而不是得到相同的结果this
?prototype
我发现,虽然这是一个令人烦恼的问题,但除非有人能告诉我它的真正含义,否则无法回答。
我知道this
大致翻译为“这个类的这个实例”,但是......是什么prototype
意思?