开发者

what is * return type in as3

I saw a method in Action script that has a return type of *

public function f(s:String):开发者_Go百科*

what does this [*] means ?


That answer is not 100% correct. There is no "untyped" and there is only a small difference between * and Object, because one could argue that Object means untyped as well since every type extends from Object. However * implies the undefined value and Object not. A big difference! This is useful for dynamic languages because this means a property of an Object can be undefined which is different from defined and null.

So for instance y is undefined in { x: null } and x is defined but without a value. And you can make use of that:

var yesNoMaybe: *;

yesNoMaybe = true;
yesNoMaybe = false;
yesNoMaybe = undefined;


The * symbol means "untyped", meaning that the type can be anything (and that the value can be undefined). Using the asterisk has the same effect as not specifying the type at all, but it's good form to use it in order to be explicit about your intention. See the language reference for more info.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜