[AS3.0] 数値・演算子アラカルト (3)

そうだ! AS3.0の数値・演算子まわりを学習しよう! :bouzu:

黒魔術じゃないよ! :boy:

:caution: 要 Flash Player 9 以上


論理和演算子

This movie requires Flash Player 9.0.0
This movie requires Flash Player 9.0.0
This movie requires Flash Player 9.0.0
This movie requires Flash Player 9.0.0
// case1
var number:Number = 4;
// case2
var number:Number = NaN;
// case3
var number:Number = 2.5;
// case4
var number:Number = 0;

var result:int = String(calc(number));

function calc(n:Number):Number {
  return n || Math.PI;
}


論理和代入演算子

This movie requires Flash Player 9.0.0
This movie requires Flash Player 9.0.0
This movie requires Flash Player 9.0.0
This movie requires Flash Player 9.0.0
// case1
var number:Number = 4;
// case2
var number:Number = NaN;
// case3
var number:Number = 2.5;
// case4
var number:Number = 0;

var result:int = String(calc(number));

function calc(n:Number):Number {
  return n ||= Math.PI;
}

こういう使い方をするらしい。 :hakase:
var piyo:Piyo;
if (piyo == null) {
  piyo = new Piyo();
}

var piyo:Piyo ||= new Piyo();