Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: Function.prototype.apply: Arguments list has wrong type (?)

Tags:

javascript

I'm getting the error Uncaught TypeError: Function.prototype.apply: Arguments list has wrong type when I use the .apply() method and I'm not sure why. My code is here.

When jsfiddle loads up, click next to the word test and hit the Enter key. The method that the error is occurring in is this.addEvent. I'm trying to have my object be the 'this' in the event's callback function.

like image 816
Justin808 Avatar asked May 13 '11 06:05

Justin808


1 Answers

You should use .call instead of .apply.

a.apply(obj, lst) is equivalent to a(lst[0], lst[1], lst[2], ...) when lst is an Array (or arguments) using obj as this.

a.call(obj, x, y, z, ...) is equivalent to a(x, y, z, ...) using obj as this.

Since e is one of the arguments, not an array of arguments, you should use .call.

like image 126
kennytm Avatar answered Sep 20 '22 13:09

kennytm