Created
January 26, 2011 14:02
-
-
Save Nutrox/796719 to your computer and use it in GitHub Desktop.
AS3 - JavaScript Style Closures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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