未定義変数の等価チェック
== null とか == undefined とか
♥0 |
Line 59 |
Modified 2011-08-30 15:41:36 |
MIT License
archived:2017-03-10 12:42:05
ActionScript3 source code
/**
* Copyright yprops ( http://wonderfl.net/user/yprops )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/xKwB
*/
package {
import flash.text.TextField;
import flash.display.Sprite;
import flash.utils.getQualifiedClassName;
public class FlashTest extends Sprite {
private var tf :TextField;
public function FlashTest() {
var vInt :int;
var vUint :uint;
var vNum :Number;
var vBool :Boolean;
var vStr :String;
var vObj :Object;
var vUdf :*;
settx("////未定義の変数の等価チェック////");
addtx("int", vInt);
addtx("uint", vUint);
addtx("Number", vNum);
addtx("Boolean", vBool);
addtx("String", vStr);
addtx("Object", vObj);
addtx("*", vUdf);
addtx("null", null);
addtx("undefined", undefined);
addtx("\"\"", "");
}
//----------------
private function settx(caption :String) :void{
tf = new TextField();
tf.width = 300;
tf.height = 400;
tf.background = true;
tf.border = true;
tf.appendText(caption + "\n");
addChild(tf);
}
private function addtx(caption :String, val :*) :void{
var cn :String = getQualifiedClassName(val);
var ts :String;
try{ ts = val.toString(); }catch(er :Error){ts = "[errored]";}
tf.appendText(
"[" + caption + "]" +
"\n\tclassname\t\t" + cn +
"\n\tvalue\t\t\t" + val +
"\n\ttoString()\t\t" + ts +
"\n\t== true\t\t\t" + (val == true) +
"\n\t=== true\t\t" + (val === true) +
"\n\t== \"\"\t\t\t" + (val == "") +
"\n\t=== \"\"\t\t\t" + (val === "") +
"\n\t== null\t\t\t" + (val == null)+
"\n\t=== null\t\t" + (val === null)+
"\n\t== undefined\t" + (val == undefined) +
"\n\t=== undefined\t" + (val === undefined) +
"\n\t== 0\t\t\t" + (val == 0)+
"\n\t=== 0\t\t\t" + (val === 0)+
"\n\n"
);
}
}
}