Javascript : Call method and Function Borrowing

Sanjana Human In Tech
1 min readJun 23, 2024

--

The call method is built in Javascript function that allows to call a function with specific ‘this’ value in arguments provided individually. It enables the explicit setting of ‘this’ inside a function and passing arguments in it.

The call method and apply method is basic difference is passing arguments.

The call method takes an arguments individually. The apply method take an argument as an array.

call method is used to define to borrow the function which is called function borrowing.

For an example :

let programme= {
language: "Hello",
message: "Javascript is synchronous programming."

printFullLangauge: function() {
console.log(this.langauge + " " + this.message);
}
}

//programme.printFullLangauge (prints "Hello Javascript is synchronous programming.")

let programmeTwo = {
name : "HI",
address: "Javascript"
}

//function borrowing
programme.printFullLangauge.call(programmeTwo);
(Prints the "HI Javascript");

also we can declare a method outside of the object too;

let programme= {
language: "Hello",
message: "Javascript is synchronous programming."
}

let printFullLangauge = function() {
console.log(this.langauge + " " + this.message);
}

//programme.printFullLangauge (prints "Hello Javascript is synchronous programming.")

let programmeTwo = {
name : "HI",
address: "Javascript"
}

//function borrowing
printFullLangauge.call(programmeTwo);
(Prints the "HI Javascript");

--

--

Sanjana Human In Tech
Sanjana Human In Tech

Written by Sanjana Human In Tech

A React Native front-end enthusiast and dedicated development engineer, eager to expand knowledge on development techniques and collaborate with others.

Responses (1)