Skip to content

Commit fab66ca

Browse files
committed
get set in js
1 parent 150f032 commit fab66ca

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

11_OOP/geterseter.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class car{
2+
constructor(brand, model, year){
3+
this.brand = brand;
4+
this.model = model;
5+
this.year = year;
6+
}
7+
get carname(){
8+
return this.brand + ' ' + this.model + ' ' + this.year;
9+
}
10+
set carname(value){
11+
this.brand = value;
12+
}
13+
}
14+
15+
let mycar = new car('ford', 'mustang', 2023);
16+
17+
mycar.carname = 'BMW' //setter
18+
19+
console.log(mycar.carname) //getter

0 commit comments

Comments
 (0)