If I have something like:
package {
public class Main() {
public function Main() {
var foo = new 开发者_运维技巧Foo();
var bar = new Bar(foo);
}
}
}
package {
public class Foo() {
public function Foo() {
}
public function doSomething() {
trace("hello");
}
}
}
package {
public class Bar(foo:Foo) {
foo.doSomething();
}
}
How many instances of "foo" do I have?
Like, do I just have one instance that "Main" and "Bar" share? Or do I actually have two instances?
You have one instance that Main and Bar share. Objects are passed by reference; to create a new Foo you would actually have to write "new Foo()" in Bar.
精彩评论