新客网 XKER.COM 2008-10-07 来源:
收藏本文
最近发现两个重写Math.round方法的实现:
Math.rand = function(l,u)
{
return Math.floor((Math.random() * (u-l+1))+l);
}
Math.prototype.rand = function(l,u)
{
return Math.floor((Math.random() * (u-l+1))+l);
}
Sample: Math.rand(1,10)
大家说这两个方法都可以吗? 那个是正确的做法?呵呵,测试一下就知道了:)

发表评论