forked from: 代入演算子の結合性
forked from 代入演算子の結合性 (diff: 21)
代入演算子の結合性のテスト b = a = 10.5の場合 b = (a = 10.5); 右辺結合性なので、b=10 になると思っていたんだが、、なんで intどうしの割り算 a/cの結果はint型になると思っていたんだが、Number型に変換されるみたい、、
ActionScript3 source code
/**
* Copyright coppieeee ( http://wonderfl.net/user/coppieeee )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/oeB3
*/
// forked from onmyownlife's 代入演算子の結合性
package {
import flash.display.Sprite;
import flash.text.*;
/**
*
* 代入演算子の結合性のテスト
*
* b = a = 10.5の場合
*
* b = (a = 10.5);
* 右辺結合性なので、b=10 になると思っていたんだが、、なんで
*
* intどうしの割り算
* a/cの結果はint型になると思っていたんだが、Number型に変換されるみたい、、
*
*/
public class FlashTest extends Sprite {
private function get d():int { return _d;}
private function set d(value:int):void {_d = value;}
private var _d:int;
public function FlashTest() {
var a:int;
var b:Number;
var c:int = 3;
a = b = 10.5;
var output:String="a = b = 10.5 >> a : "+a+" , b : "+b;
var txt:Text =new Text (10,10,output,this);
b = a = 10.5;
output="b = a = 10.5 >> a : "+a+" , b : "+b;
txt=new Text (10,30,output,this);
output="a/c = "+a/c;
txt=new Text (10,50,output,this);
b = (a = 10.5);
output="b = (a = 10.5) >> a : "+a+" , b : "+b;
txt=new Text (10,70,output,this);
//優先順位が逆転してるんじゃなくて、(a = 10.5)の戻り値が10.5ではないかと予想。
output="(a = 10.5) >> ( a = 10.5) : " + ( a = 10.5) + " , a :"+a;
txt=new Text (10,90,output,this);
//やっぱりね
output="(d = 10.5) >> ( d = 10.5) : " + ( d = 10.5) + " , d :"+d;
txt=new Text (10,110,output,this);
//getter,setterでも同じらしい。
}
}
}
import flash.text.*;
import flash.display.*;
class Text extends Sprite{
public function Text(x:Number,y:Number,value:String,parent:Sprite){
var txt:TextField=new TextField();
txt.text=value;
txt.x=x;
txt.y=y;
txt.width=200;
parent.addChild(txt);
}
}
