javascript - Function.prototype.apply left me with undefined is not a function error -


i have simple function js so:

function simple(){  } 

i got undefined not function error when did this:

simple.prototype.apply(null,arguments); 

but when did this:

simple.apply(null,arguments); 

i did not error, why on earth that?

the .prototype object not have .apply() method why first example not work. .apply() method on function objects only. see mdn reference .apply(). instead, this:

functionname.apply(xxx,yyy)  

there cases might see function on prototype object being used .apply() such as:

array.prototype.slice.apply(xxx,yyy) 

but, again, that's calling .apply() on function since array.prototype.slice function.


in specific example, simple function. so, if want call specific this value and/or pass array of arguments, proper syntax is:

simple.apply(xxxx, yyy) 

that why syntax works - because it's proper syntax .apply().


perhaps if share problem you're trying solve , show relevant code can more specifically.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -