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
Decorators for assignment expressions? const/let declarations? #51
Comments
Use case: runtime guards This came up at es-discuss "Proposal to add symbol: hasInstanceStrict" that
to which TJCrowser replied
The response was that decorators do not allow vetting a value assigned to a local as in const c: PrimitiveNumber = sum(1, 2); This issue came up later on:
|
Propose to use such syntax:
|
I'd prefer to leave it as a follow on. |
I'd like to suggest changing the const decorators extension to include a With a getter on const, you could do lazy evaluation: const @lazy maybeNeeded = () => calc(...args);
if (day === "Sunday") { result += f(maybeNeeded); }
if (month === "June") { result += g(maybeNeeded); } function lazy({ get, set, value }, { kind }) {
let ready = false;
switch (kind) {
case "const": return { get: getLazy, value };
case "let": return { get: getLazy, set: setLazy, value };
default: throw Error("bad kind");
}
function getLazy() {
if (!ready) value = get()(), ready = true;
return value;
}
function setLazy(v) {
set(v);
ready = false;
}
} On another note, can the whole semantics of the I would instead suggest // add +1 when reading
function lazyInc({ get, set }) { return { get: v => get(v) + 1, set }; }
// add +1 on initialization and assignment
function eagerInc({ get, set }) { return { get, set: v => set(v + 1) }; } |
Previous discussion: tc39/proposal-decorators-previous#32
OK to leave as a follow-on proposal?
The text was updated successfully, but these errors were encountered: