Getting error CreateListFromArrayLike called on non-object when trying to use .apply()

前端 未结 3 525
北海茫月
北海茫月 2020-12-28 12:45

I\'ve created a simple little route parsing function so that I can keep my code clean and easily maintainable, this is the little function that gets ran when the app starts

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-28 13:16

    You need to send the params as an array, like this:

    app[method.toLowerCase()].apply(this, [path, fn]);

    If you want to send an arguments list you need to use call:

    app[method.toLowerCase()].call(this, path, fn);

    Source: call, apply

提交回复
热议问题