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.

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more