Created
February 11, 2014 14:13
-
-
Save rayyee/8935553 to your computer and use it in GitHub Desktop.
as3 prototype test.
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
//给数组原型增加一个获取随机数组元素的方法:randomItem | |
Array.prototype.getRandomItem = function(): * | |
{ | |
return this[Math.floor(Math.random() * this.length)]; | |
}; | |
//这里设置这个方法不可被(for...in、foreach...in)枚举,非常重要! | |
Array.prototype.setPropertyIsEnumerable('getRandomItem', false); | |
var arr:Array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
trace(arr.getRandomItem()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment