Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Javascript mehods
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Call -> In Javascript with the call() method you can write a method that can be used on different objects.
Apply -> Apply method also works but the only difference is using the apply method the passing arguments could be an array, refer below code.
Bind -> bind method returns a method instance instead of result value, after that need to execute a bound method with arguments.

Here's the example of all the three above

var obj={
num : 2
}
var add = function(num2,num3,num4){
return this.num + num2 + num3 + num4;
}
var arr=[3,4,5];
//Call method
console.log(add.call(obj,3,4,5)); //Output : 14
//Apply method
console.log(add.apply(obj,arr)); //Output : 14
//bind Method
var bound = add.bind(obj);
console.log(bound(3,4,5));