Skip to content

Instantly share code, notes, and snippets.

@rayyee
Created February 11, 2014 14:13
Show Gist options
  • Save rayyee/8935553 to your computer and use it in GitHub Desktop.
Save rayyee/8935553 to your computer and use it in GitHub Desktop.
as3 prototype test.
//给数组原型增加一个获取随机数组元素的方法: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