JavaScript 高阶函数

时间:2014-08-29 01:18:16   收藏:0   阅读:298

 

 

; Run = function ()
  {
    ; return Array.prototype.splice.call( arguments, -1 )[0].apply( this, arguments )
  }

; Loop = function ()
  {
    var
      count = -1
    , end   = arguments.length -1
    , _func = arguments[ end ]

    ; while ( ++count < end )
      {
        ; _func.apply( this, arguments[ count ] )
      }
  }

; Run( 2, 3, 4, function( x, y, z )
  {
      console.log( x*y*z )
  })
; Run.call( { name : ‘Run‘ }, 2, 3, 4, function( x, y, z )
  {
      console.log( this, x*y*z )
  })
; Loop( [ 2, 3 ], [ 4, 5 ], function ( x, y )
  {
    ; console.log( x*y )
  })
; Loop.call( { name : ‘Loop‘ }, [ 2, 3 ], [ 4, 5 ], function ( x, y )
  {
    ; console.log( this, x*y )
  })

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!