Open outofambit opened 2 months ago
I think these are good changes and in general we should be eliminating any thing using aria = aria || {};
.
Our biggest issue is having a plan to update legacy examples to the new coding practices.
@jongund Glad to hear that, thank you for the feedback. I was actually suggesting we standardize on const aria = aria || {};
in each file since all of these examples are at some point running in the context of a larger page and I thought that would be best to have some encapsulation for classes and helper methods. If you have other idea for how to address that I would be very interested to hear them!
The ARIA Authoring Practices (APG) Task Force just discussed Code guide proposals
.
Thanks for posting the log in here - I'm currently looking into the official best practices. I'll post my updates in here and if you want I'll present them in the meeting next week!
Here are some of my findings:
"Use let and const instead of var"
Recommendation: ✅ I agree that we should replace / correct snippets of the old style. Using var
is ignorant of the consequences and dangerous in many if not most cases.
"Use
for...of
instead offor
loops that don't rely on an index for their logic"
Recommendation: ✅ Personally I'd generally recommend using the newer for...of
/ for...in
variants as they are less error prone to off-by-ones for example, especially when just writing example code without extensive testing.
"Update class syntax to use class fields (as in, replace
this.foo;
withfoo;
in class declarations)"
Recommendation: ❌ The code guide directly comments on this: Class methods should use this or be made into a static method
. We should either follow the guide completely or look for another one. Although I agree that removing this
from the examples would reduce redundancy and give our customers less to read, using var
or leaving out the this
keyword may lead to name clashes that can go unnoticed - so it's probably best to stick with the guide's recommendations.
"Class methods should use this or be made into a static method unless an external library or framework requires using specific non-static methods. Being an instance method should indicate that it behaves differently based on properties of the receiver. eslint: class-methods-use-this" Quote from 9.7
"Use
static
methods andblocks
for shared utilities specific to an example."
Recommendation: ✅ The code guide does not contain this topic - but in my opinion it's a good idea to use static
init blocks (I'd call them static constructors
, but that might just be me, as my background is in C++) so every variable is scoped to the class / type it belongs to and doesn't clutter the global namespace. In that regard it's similar to the var
vs. let
debate.
"Standardize on using a global object when creating new functions and classes. A lot of examples do this but some do not and it is not called out in the code guide. (For example, use const aria = aria || {};)"
Recommendation: I don't really have an opinion on this - I'd like to see some examples first. @outofambit can you share one or two maybe so I can see what exactly you would like to change?
PS: I hope this post is to your liking. As I'm still new to the group I tried to make sure to go into as much detail as seemed reasonable, but feel free to critique me 😉
The ARIA Authoring Practices (APG) Task Force just discussed Code guide updates
.
Hi, here are some thoughts on changes we could make to the code guide to incorporate newer JS features into them. Normally I would open a PR to propose these, but since it is a wiki page, this seemed like the right place to articulate these first.
I read through the code guide and did some perusing through the current set of examples to get a sense of what the general usage and patterns were and would like to propose adding the following to the JavaScript section of the Code Guide:
let
andconst
instead ofvar
for...of
instead offor
loops that don't rely on an index for their logicthis.foo;
withfoo;
in class declarations)const aria = aria || {};
)