http://apps.hi.baidu.com/share/detail/15482416

--------------------------------------------------

js中prototype用法

 
  当然,也可以进一步扩充,得出响应的小时、分钟,甚至是秒。

(3) Number.fact()
  作用:某一数字的阶乘
  实现方法:
  Number.prototype.fact=function(){
         var num = Math.floor(this);
         if(num<0)return NaN;
         if(num==0 || num==1)
             return 1;
         else
             return (num*(num-1).fact());
     }
  试验:alert((4).fact()) -> 显示 24
  这个方法主要是说明了递归的方法在 prototype 方法中也是可行的!
http://hi.baidu.com/3seefans/blog/item/1761b3f56ed3d02fbc3109e4.html

相关文章:

  • 2021-10-27
  • 2022-02-15
  • 2021-10-25
  • 2021-10-04
  • 2021-07-14
  • 2022-12-23
  • 2021-10-17
猜你喜欢
  • 2021-08-14
  • 2021-08-10
  • 2022-02-23
相关资源
相似解决方案