-
Notifications
You must be signed in to change notification settings - Fork 207
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
Determine our function/method definition syntax style #524
Comments
The "classic" style is also close to the getter/setter syntax |
"classic" style is officially called "concise method syntax". |
Here's my thoughts:
To sum up, I think it's as easy or easier to use, and puts us into the "up-and-coming" well-written JavaScript category rather than the outdated category. @erights what do you think? |
I mostly agree with both @dtribble 's and @katelynsills 's +/- points above. Some additional points: @DavidBruant 's point about getter/setter syntax is valid and does argue in favor of concise method syntax. There is no practical arrow function syntax for expressing accessors. Jessie does admit accessors, though perhaps it should not. From recent conversations with @michaelfig though, we are more likely to keep accessors in Jessie and to extend captp to make use of them. All functions in JavaScript Looking at the overall picture above I'd be on the fence though leaning more towards arrow-only. However, I've been using arrow-only style for a while now as an experiment. I like it. For me this is a tie breaker. But, to @DavidBruant 's point, my position isn't really arrow-only because I still want to admit accessors. |
See also endojs/endo#708 (review) , which is about |
@erights @dtribble @kriskowal , is auto-hardening exports consistent with the policy / norm that our JS dialect has the same semantics as standard JS? |
@kriskowal and I talked about @dtribble 's idea for rescuing As with Without const obj = {
add(a, b) { return a + b; },
}; vs const obj = {
add: (a, b) => a + b,
}; more than makes up for the extra verbosity of the method-with-body case: const obj = {
add(a, b) {
x = a;
return a + b;
},
}; vs const obj = {
add: (a, b) => {
x = a;
return a + b;
},
}; |
Remember that part of the goal of the Jessie definition is that it be extremely easy to implement Jessie in any conventional sequential imperative language by a simple eval/apply style interpreter. This is why Jessie already omits A Jessie implementation must then implement three kinds of functions: builtin functions, normal arrow functions, and async arrow functions. Our overall programming style does not prohibit other options when there's a reason --- typically interfacing to a legacy something --- but it would be outside our normal practice, and outside Jessie. For code opting into Jessie rules, these non-Jessie options would indeed be prohibited. But that's part of why we allow code that does not opt into Jessie rules. And why we define the semantics of Jessie under the assumption that Jessie objects co-exist with SES objects. |
I say we omit concise methods from Jessie. Thus, Jessie is left with only those three kinds of functions I listed: builtins, normal arrows, and async arrows (with only top-of-function |
I added some best practice docs: Arrow Function Style |
Right now we have a mix of classic method definition and arrow function. We should ideally have a single style, but there may be driving cases for each. We need to identify those and converge on a consistent usage.
Resolved: arrow function style
Jun 7
best practice docs: Arrow Function Style
The text was updated successfully, but these errors were encountered: