I’ll keep this brief.
I’ve been noticing a lot of public code snippets out there which declare const
s using the
arrow function syntax;
const addOne = (number) => {
return number + 1;
}
As opposed to the classic pre-ES2015 form,
function addOne(number) {
return number + 1;
}
My use of the term “classic” reveals my bias,
as opposed to calling it “ancient” or “crappy old”.
There are two things I prefer about the classic form;
- You know instantly that it’s a
Function
by just looking at the line
- Why capture a scope context that you never use?
Now, to be clear, I’m totally down with something along these lines;
Transformer.prototype.transform = function transform(nouns) {
const renamer = (noun) => {
const { renameMap } = this;
return (renameMap.has(noun) ? renameMap.get(noun) : noun);
};
const inclusions = (noun) => this.includeSet.has(noun);
if (this.shouldRename) {
// filter both inbound & outbound
return nouns.filter(inclusions).map(renamer).filter(inclusions);
}
return nouns.filter(inclusions);
};
It’s a convoluted example, and could be approached very differently …
but as written it makes a lot of sense to declare a few Function
const
s that inherit the scope context.
I’m all in favor of adopting a modern JavaScript syntax, as long as it serves a purpose in the code.
You saw me up there deconstructing an Object with reckless abandon, right?
I find that syntax much cleaner and more expressive than a this
assignment, and I’ll choose it in a heartbeat.
But I propose that an old-school function
declaration is the cleaner, more expressive style when either one could meet your needs.
NOTE: If your screen reader is reading this, please
contact me at admin@cantremember.com ... because it shouldn't.
FIXME: build this dynamically based upon the maximum content in any sub-Element of this Element.
I will call this my "Safari Reader Counterweight".
In some of my Posts, I have huge code excerpts, etc.
Safari Reader, at least in iOS, will identify the 'main Element', the one it features, based upon its content length.
Sometimes those code excerpts get identified as the 'main Element', and the Post is borked in Safari Reader mode.
This is a counter-weight; it gives the <main> Element additional content so that it gets featured, algorithmically.
Yes, it increases the payload of every page (@see FIXME above).
But not by
that much.
Then again, this is a guess as to how much content any given Element could contain.
If it's not enough,
BOOM, Safari Reader looks like crap.
So, here's a great article on
how to enable Safari Reader on your site.
It's mostly guesswork, but those guesses helped me debug this obtuse goddamn problem.
Oh, and look,
you can enter and exit Reader programmatically.
JavaScript can fix anything.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.
I promise I will never cut-and-paste lines of text simply to add Element payload.