TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript Function call() Method

JavaScript Function call() Method with example on javascript function object, javascript tutorial, apply(), bind(), call(), toString(), toSource(), isgenerator(), javascript handler, javascript reflect, object, number etc.

<< Back to JAVASCRIPT

JavaScript Function call() method

The JavaScript Function call() method is used to call a function contains this value and an argument provided individually. Unlike apply() method, it accepts the argument list.

Syntax

function.call(thisArg, arg1,arg2,....,argn)

Parameter

thisArg - It is optional. The this value is given for the call to function.

arg1,arg2,...,argn - It is optional. It represents the arguments for the function.

Return Value

It returns the result of the calling function along provided this value and arguments.

JavaScript Function call() method Example

Example 1

Let's see a simple example of call() method.

<script>
function Emp(id,name) {
  this.id = id;	
  this.name = name;
}
function PermanentEmp(id,name) {
 Emp.call(this,id,name);
}
document.writeln(new PermanentEmp(101,"John Martin").name);
</script>
Test it Now

Output:

John Martin

Example 2

Let's see an example of call() method.

<script>
function Emp(id,name) {
  this.id = id;
  this.name = name;
}
function PermanentEmp(id,name) {
 Emp.call(this,id,name);
}
function TemporaryEmp(id,name) {
 Emp.call(this,id,name);
}
var p_emp=new PermanentEmp(101,"John Martin");
var t_emp=new TemporaryEmp(201,"Duke William")
document.writeln(p_emp.id+" "+p_emp.name+"<br>");
document.writeln(t_emp.id+" "+t_emp.name);</script>
Test it Now

Output:

101 John Martin
201 Duke William





Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf