From a6c16efbfc33b9eaea643bae15211ecc3f19daed Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Mon, 15 Sep 2025 13:19:25 -0700 Subject: [PATCH] Refactor: Clarify implicit return behavior and simplify example --- index.html | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 0ed3809..a955019 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,7 @@ - + @@ -137,12 +137,15 @@ counter: { inc: { value = value + 1 // Mutates parent's private state - _("The count is now: " + value) + } + + get: { + value // The last expression is implicitly returned } } -counter.inc() // Prints "The count is now: 1" -counter.inc() // Prints "The count is now: 2" +counter.inc() +_(counter.get()) // Prints 1 \`\`\` ### Blocks with Parameters @@ -238,13 +241,15 @@ sum(5, mul(2, 3)) // 11 ## Method Chaining -By default, a method call on a Block returns the Block itself (\`this\`), enabling fluent, chainable interfaces. To return a different value and break the chain, use the return symbol \`^\`. +A Block's return behavior is designed for fluency. It implicitly returns the value of its last expression. If the last expression does not yield a value (such as an assignment), the Block returns itself (\`this\`) by default, enabling method chaining. The \`^\` symbol is used for an explicit or early return from any point in the Block. \`\`\`javascript calculator: { #total: 0 + // Last expression is an assignment, so 'this' is returned add: (n) { total = total + n } sub: (n) { total = total - n } + // Last expression is a value, which is returned get: { ^ total } }