//比较函数语句定义方式与函数表达式定义语句中this的区别
//var num:int = 3;
//function testThisA(){
// trace(num);
// trace(this.num);
// trace(this);
//}
//var testThisB:Function = function(){
// trace(num);
// trace(this.num);
// trace(this);
//}
//var obj:Object = {num:300};
//obj.testB = testThisB;
//obj.testA = testThisA;
//
//testThisA();
//obj.testA();
//testThisA.apply(obj);
//
//testThisB();
//obj.testB();
//testThisB.apply(obj);
//按值还是按引用来传入参数
//function test(valuePara:int , referencePara:Array):void{
// valuePara = 100;
// referencePara.push(100);
//}
//
//var a:int = 5;
//var b:Array = [1,2,3];
//test(a,b);
//trace(a);
//trace(b);
//4.2.2 设置参数默认值
//function test(a:int = 3,b:int =2,c:int = 1):void{
// trace(a+b+c);
//}
//test();//6
//test(9);//12
//test(2,9);//12
//test(1,2,3);//6
//4.2.3 访问参数信息和...(rest)关键字
//function test(a:int = 3,b:int = 2,c:int = 1):void{
// trace("参数长度:"+arguments.length);
// trace(a+b+c);
// if(a+b+c >0) arguments.callee(a-1,b-1,c-1);
//}
//test();
//function testA(...paras):void{
// trace("参数长度:"+paras.length);
// for(var i in paras) trace(paras[i]);
//}
//testA(1,[2,3],"String type");
//
//function testB(firstPara:String,...agrs):void{
// trace(agrs.length);
// for(var i in agrs) trace(firstPara +":"+agrs[i]);
//}
//testB("B test",[100,200],1000,"Foo");
//4.3 函数的本质
//4.3.1 函数语句定义法定义函数对象本质
//import flash.utils.getQualifiedClassName;
//trace(getQualifiedClassName(aFunc));
//trace(getQualifiedSuperclassName(aFunc));
//trace(aFunc is Function);
//trace(aFunc is Object);
//function aFunc(){ trace ("This is aFunc!Excuted!");}
//4.3.2 函数表达式定义法定义的函数对象本质
//import flash.utils.getQualifiedClassName;
//var aFunc:Function = function(){
// trace("This is bFunc!Excuted!");
//}
//trace(getQualifiedClassName(aFunc));
//trace(aFunc is Function);
//trace(aFunc is Object);
//4.4 函数高级使用技巧
//4.4.1 技巧一:代理函数对象
//var kingdaFunc:Function;
//var sex:String = "male";
//if(sex == "male"){
// kingdaFunc = maleFunc;
//}else{
// kingdaFunc = femaleFunc;
//}
//kingdaFunc();
//function maleFunc(){
// trace("I am a boy");}
//function femaleFunc(){
// trace("I am a girl");}
//4.4.2 技巧二:建立函数执行队列
//var funcAry:Array = new Array();
//funcAry.push(aFunc);
//funcAry.push(bFunc);
//funcAry.push(cFunc);
//
//var originObject:Object = new Object();
//var execQueue:Number = funcAry.length;
//
//var operationAry:Array = [2,1,0];
//for(var k:Number = 0;k<operationAry.length;k++){
// funcAry[operationAry[k]](originObject);
//}
//
//for(var i:Number = 0;i<funcAry.length;i++){
// funcAry[i](originObject);
//}
//for(var j in originObject){
// trace(j+":"+originObject[j]);
//}
//
//function aFunc(eO:Object){ eO.aFuncExected = true; trace("aFunc()");}
//function bFunc(eO:Object){eO.bFuncExected = true; trace("bFunc()");}
//function cFunc(eO:Object){eO.cFuncExected = true ; trace("cFunc()");}
//4.4.4 技巧三:利用函数返回函数
//chooseFuncBy("A")("A func has only one parameter.");
//chooseFuncBy("B")("B func has two parameter.","No.2 parameter");
//chooseFuncBy("wu lala")("I choose A function");
//
//var withObj:Object = new Object();
//var myObj:Object = {name:"黑羽",blog:"http://www.kingda.org",hobby:"Starcraft"};
//chooseFuncBy(withObj)(myObj);
//
//function chooseFuncBy(input:*):Function{
// if(!(input is String)){ return objectFunc; }
// switch(input){
// case "A":
// return aFunc;
// case "B":
// return bFunc;
// default:
// return kingdaFunc;
// }
//}
//function aFunc(nS:String):void{ trace("aFunc():"+nS);}
//function bFunc(nS:String,nP:String):void{
// trace("bFunc():"+nS+"one more Parameter:"+nP);}
//function kingdaFunc(...rest):void{
// trace("Welcome to Kingda.org! My blog");}
//function objectFunc(kingdaObj:Object):void{
// trace("objectFunc():");
// for (var i in kingdaObj){
// trace(i+":"+kingdaObj[i]);} }
//4.4.4 技巧四:函数动态添加实例属性
//var shot:Function = function():void{
// shot['times']++;
// trace("Shot(): times:"+ shot['times']);}
//
// shot['times'] = 0;
// shot();
// shot();
// shot();
//4.4.5 技巧五:函数对象动态添加实例方法
//var shot:Function = function():void{
// shot['times']++;
// trace("Shot():times:"+shot['times']);
// shot['reload']();}
//
// shot['times'] = 0;
// shot['reload']=function() {
// trace("reload:"+this['times']);
// if(this['times']>3){
// this['times']=0;} }
//
//shot['reload']();
//shot();
//shot();
//shot();
//shot();
//shot();
//shot();