Loading Please Wait...

Logo Lynxsia IT Solutions

JavaScript Function Call

JS Function Call

With the call() method, you can write a method that can be used on different objects.

The JavaScript call() Method

The call() method is a predefined JavaScript method.

It can be used to invoke (call) a method with an owner object as an argument (parameter).

With call(), an object can use a method belonging to another object.

					 
        
          const person = {
            fullName: function() {
              return this.firstName + " " + this.lastName;
            }
          }
          const person1 = {
            firstName:"John",
            lastName: "Doe"
          }
          const person2 = {
            firstName:"Mary",
            lastName: "Doe"
          }

          person.fullName.call(person1); // "John Doe"
          person.fullName.call(person2); // "Mary Doe"
        
      
The call() Method with Arguments

The call() method can accept arguments

					 
        
          const person = {
            fullName: function(city, country) {
              return this.firstName + " " + this.lastName + "," + city + "," + country;
            }
          }

          const person1 = {
            firstName:"John",
            lastName: "Doe"
          }

          person.fullName.call(person1, "Oslo", "Norway"); // John Doe,Oslo,Norway
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved