Skip to content

Instantly share code, notes, and snippets.

@Nutrox
Created January 26, 2011 14:02
Show Gist options
  • Select an option

  • Save Nutrox/796719 to your computer and use it in GitHub Desktop.

Select an option

Save Nutrox/796719 to your computer and use it in GitHub Desktop.
AS3 - JavaScript Style Closures
var window:Object = {};
new function():void {
var shared:Number = 100;
/**
*/
function Foo():void {
this.getNumber = function():Number {
return shared ++;
}
}
/**
*/
function Bob():void {
}
Bob.prototype = new Foo();
window.foo = new Foo();
window.bob = new Bob();
}
trace( window.foo.getNumber() ); // 100
trace( window.bob.getNumber() ); // 101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment