forked from uciharis/materi_masEko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path44_this.js
executable file
·29 lines (26 loc) · 852 Bytes
/
44_this.js
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
//this adalah sebuah metode mereferensi objek milik siapa
//dalam objek metode, this mereferensi ke objek pemilik functionnya
//global scope, this mereferensi ke global objek ( di browser biasanya ke Window)
//dalam function, this merefererensi ke global objek (di browser biasanya window)
//pada strict mode, this adalah undefined
//dalam event, this mereferensi ke elemen yang menerima event (materi DOM)
//this di global scope
console.log(this); //this merefer ke windows
function sempel(){
console.log(this);
function iner(){
console.log(this);
}
iner();
}
sempel();
//-------------------------
//this di objek metod
const person= { //this refers ke objek
nama: "eko",
sayHi: function(value){
console.log(`hello ${value} namaku adlah ${this.nama}`);
}
};
person.sayHi("budi");
person.sayHi("jokorok");