DEV Community

Joe Steinbring
Joe Steinbring

Posted on • Originally published at blog.jws.app on

Prototype.call() vs Prototype.apply()

This is going to be a relatively short post. We have been doing a lot of [x] vs [y] vs [z] posts on the main blog and this one is no different. Today, I figured that we would look at Prototype.call() vs Prototype.apply(). Both apply() and call() are used to invoke functions. The difference is that call uses a comma separated list of arguments and apply uses an array of arguments.

Prototype.call() example:

Prototype.apply() example:

For the sake of clarity, both examples do the same thing beyond the one difference. They both have teachers, students, and persons but where one uses Person.apply(this, [fname, lname]); the other one uses Person.call(this, fname, lname);.

Have a question, comment, etc? Feel free to drop a comment, below.

The post Prototype.call() vs Prototype.apply() first appeared on Blog.jws.

Top comments (0)