search

Home  >  Q&A  >  body text

javascript - function passed as parameter call error

code show as below

var f = function(call,args){
    call(args);
}

When executing f(console.log,123), there is no problem.
But when executing f(loaction.reload,true), an error is reported.
Error message As followsUncaught TypeError: Illegal invocation

phpcn_u1582phpcn_u15822748 days ago392

reply all(2)I'll reply

  • PHPz

    PHPz2017-05-18 11:04:38

    f(loaction.reload.bind(location),true)

    Explain that the reload method cannot be executed without the location object.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-18 11:04:38

    for instance:

    location.reload.call(location, true)

    reply
    0
  • Cancelreply