Archive for December 8th, 2011

 

 

 

 

 

 

 

I been writing JavaScript recently and had to conjure up the older syntax I'd usually write in ActionScript 2
This post is possibly "beating a dead horse" but I'll post it anyway.

JavaScript or ActionScript 2

  1. function isArray(o)
  2. {
  3. return o instanceof Array;
  4.  
  5. //Alternative way
  6. //return Object(o.constructor) == [].constructor;
  7. }
  8.  
  9. var A=new Array();
  10. var B=new Object();
  11. var C="dog";
  12. var D=function(){};
  13.  
  14. alert(isArray(A)+","+isArray(B)+","+isArray(C)+","+isArray(D));
  15.  
  16. //Outputs: true,false,false,false

ActionScript 3

  1. function isArray(o:Object=null):Boolean
  2. {
  3. return o is Array;
  4. }
  5.  
  6. var A:Array=new Array();
  7. var B:Object=new Object();
  8. var C:String="dog";
  9. var D:Function=function(){};
  10.  
  11. trace(isArray(A)+","+isArray(B)+","+isArray(C)+","+isArray(D));
  12.  
  13. //Outputs: true,false,false,false

Comments No Comments »

Thanks for visiting www.keith-hair.net