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

前端 未结 3 503
北海茫月
北海茫月 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:00

    I have the same problem, so i verified that node_modules/socket.io/lib/socket.js was received

    Socket.prototype.onevent = function(packet){
      var args = packet.data || [];
      debug('emitting event %j', args);
    
      if (null != packet.id) {
        debug('attaching ack callback to event');
        args.push(this.ack(packet.id));
      }
    
      emit.apply(this, args);
    };

    so i changed to:

    Socket.prototype.onevent = function(packet){
      var args = packet.data || [];
      debug('emitting event %j', args);
        
      if (null != packet.id) {
      debug('attaching ack callback to event');
      args.push(this.ack(packet.id));
      }
        
      emit.apply(this, [args]);
     };  

    it's solve to me

    0 讨论(0)
  • 2020-12-28 13:15

    Fixed it by changing:

    eval.apply(this, 'p1', 'p2')

    to:

    eval.apply(this, ['p1', 'p2'])

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题