-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
31 lines (26 loc) · 913 Bytes
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>The Difference Between Call and Apply in JavaScript</title>
<script>
var var1 = {myName: "ABC", };
var var2 = {myName: "XYZ"};
function preview(par1, par2) {
alert(this.myName + '-' + par1 + '-' + par2);
console.log(this.myName, par1, par2);
}
//using call as given below
preview.call(var1, "First", "Second"); //output: ABC First Second
//using apply as given below
preview.apply(var2, ["First", "Second"]); //output: XYZ First Second
//using basic as given below
preview("First", "Second");//output: undefined "First", "Second"
</script>
</head>
<body>
<div>
<h3>Refresh the page and see the alert result or go to console window and see the result.</h3>
</div>
</body>
</html>