AS3: cast or “as”?

前端 未结 8 1707
天命终不由人
天命终不由人 2020-11-30 10:25

Is there any difference of use, efficiency or background technique between

var mc:MovieClip = MovieClip(getChildByName(\"mc\"));

and

<
8条回答
  •  暖寄归人
    2020-11-30 10:56

    Prefer the use of a cast to the use of the as operator. Use the as operator only if the coercion might fail and you want the expression to evaluate to null instead of throwing an exception.

    Do this:

    IUIComponent(child).document
    

    Not this:

    (child as IUIComponent).document
    

    Coding Conventions

提交回复
热议问题