Skip to content

Update article.md #1200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update article.md
把容量范围(#waterLimited)和当前水量(#waterAmount)分开,是不是更清晰一些。
  • Loading branch information
Zcper authored Mar 14, 2024
commit 80b4ce2581625efdebbd2425100beec04bf02714
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,26 @@ new CoffeeMachine().setWaterAmount(100);
class CoffeeMachine {
*!*
#waterLimit = 200;
#waterAmount = 0;
*/!*

*!*
#fixWaterAmount(value) {
if (value < 0) return 0;
if (value > this.#waterLimit) return this.#waterLimit;
return value; // 在范围内的值直接返回
}
*/!*

setWaterAmount(value) {
this.#waterLimit = this.#fixWaterAmount(value);
this.#waterAmount = this.#fixWaterAmount(value);
}
}

getWaterAmount() {
return this.#waterAmount;
}

let coffeeMachine = new CoffeeMachine();

*!*
Expand Down