Created
June 22, 2009 19:46
-
-
Save gabriel-laet/134152 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Monkey patch for flash.utils.Dictionary | |
* @example Basic usage:<listing version="3.0"> | |
* var user:Dictionary = new Dictionary(); | |
* user.name = "Gabriel Laet"; | |
* user.website = "http://gabriellaet.com"; | |
* trace(user.length()); | |
* trace(user.keys()); | |
* trace(user.values()); | |
* </listing> | |
* | |
*/ | |
//TODO: has_key, setDefault, get, update, clear, copy | |
var dict:Object = Dictionary.prototype; | |
dict.length = function():int{ | |
return this.keys().length; | |
}; | |
dict.keys = function():Array | |
{ | |
var k:Array = []; | |
for(var key:String in this) k.push(key); | |
return k; | |
}; | |
dict.values = function():Array | |
{ | |
var v:Array = []; | |
for each(var value:* in this) v.push(value); | |
return v; | |
}; | |
dict.setPropertyIsEnumerable("length", false); | |
dict.setPropertyIsEnumerable("keys", false); | |
dict.setPropertyIsEnumerable("values", false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment