-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript10.js
More file actions
55 lines (46 loc) · 1.47 KB
/
script10.js
File metadata and controls
55 lines (46 loc) · 1.47 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
console.log("this keyword");
//this refrence to the object that is currently calling the functions.
//inside a method
//this ===(to object that is calling method)
// const user ={
// firstName:"sandhya",
// getName: function(){
// return this.firstName;
// }
// }
// user.getName();//sandhya
//inside a function declaration/expression
// function display(){
// console.log(this);
// }
// display();//here this === window object
//with strict mode
// "use strict";
// function display(){
// console.log(this);
// }
// display();//here this===undefined
//with arrow function
//it does not have their own property they take the value from the surrounding
//function and if sunrrounding function is not present it will point to global object
// const display = () =>{
// console.log(this);
// }
// display();//window
// const user ={
// firstname:"sandhya",
// getname: function(){
// setTimeout(() => {
// console.log(this.firstname);
// },2000);
// }
// }
// user.getname();//sandhya here its is usser object
//with event listener this===object(on which handler is attached)
// document.getElementById('btn').addEventListener('click',function(){
// console.log(this);
// });
//click handler is atteched to the button object
//explicit binding
//call(),apply(),bind() are predefine medthods.
//they can used to call an object method with another object as an argument