Actionscript:
-
var Box:Function = {
-
constructor : function(color:uint, w:Number, h:Number):void {
-
this.color = color;
-
this.s = new Shape();
-
with(this.s.graphics) beginFill(this.color), drawRect(0,0,w,h);
-
addChild(this.s);
-
-
this.setLoc = function(x:Number, y:Number):void{
-
this.s.x = x;
-
this.s.y = y;
-
}
-
}
-
}.constructor;
-
-
var box0:Object = new Box(0xFF0000, 100, 100);
-
-
box0.setLoc(100, 10);
-
-
var box1:Object = new Box(0x000000, 50, 50);
-
-
box1.setLoc(210, 10);
This snippet makes use of Object.constructor() to allow creation of Object instances using the new keyword. This is for fun only, I don't recommend this over actual Classes.