scrimba
Learn Modern JavaScript
Use getters and setters to Control Access to an Object
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Use getters and setters to Control Access to an Object
AboutCommentsNotes
Use getters and setters to Control Access to an Object
Expand for more info
index.js
run
preview
console
class Book {
constructor(author) {
this._author = author;
}
// getter
get writer(){
return this._author;
}
// setter
set writer(updatedAuthor){
this._author = updatedAuthor;
}
}

function makeClass() {

return Thermostat;
}

const Thermostat = makeClass();
const thermos = new Thermostat(76);
let temp = thermos.temperature;
thermos.temperature = 26;
temp = thermos.temperature;
Console
TypeError: Thermostat is not a constructor (/index.js:12)
,
index.html
-5:10