-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay7thiskeyword.html
39 lines (34 loc) · 1.25 KB
/
Day7thiskeyword.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
32
33
34
35
36
37
38
39
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Day7
</title>
</head>
<body>
<script>
//this keyword in javascript
// 1.this inside object funtion ,it refers to object
// 2. this inside simple factory funtion , it refers to gobal / window object
let keyprop={
firstname:"ponmani",
lastname:"venkatesan",
name(){
console.log(keyprop.firstname);// it will get us value but bad practice
console.log(this.firstname);// good to use this ,inside object fun ,so refers to object
}
}
keyprop.name();
function newname(){
console.log(this);// it will refers to window object , because it is simple funtion
}
newname();
//this in construtor
function Profile(name){ // eventhough simple function, it is a construtor so ,this refers to object
this.name=name;
console.log(this);//refers to object
}
let namevalue=new Profile("mani");//new will create new object puts this inside it.
</script>
</body>
</html>