Last active
November 5, 2018 03:36
-
-
Save quangkeu95/ea147739e2c2db6d561903b5b0babaea to your computer and use it in GitHub Desktop.
Smart Setter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let employee = { | |
get workDuration() { | |
return this._workDuration; | |
}, | |
set workDuration(value) { | |
if (value.length > 8) { | |
console.log("Work duration is too much, maximum 8 hours is allowed"); | |
return; | |
} | |
this._workDuration = value; | |
} | |
}; | |
employee.workDuration = 6; | |
console.log(employee.workDuration); // 6 | |
employee.workDuration = 10; // Work duration is too much... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment