JavaScript used to be a nice prototype based programming language...
Anyway, I'm more interested in how this site is being published. I'm on iOS and in vertical format words are cutoff with dashes properly for that format and when I switch to landscape other words are cut off that fit that format.
Is this some simple css attribute I missed completely?
> JavaScript used to be a nice prototype based programming language
"this" binding depending on the call site never made sense to me. Why do you think it became worse with arrow functions and Function.prototype.bind?
In case I'm not misunderstanding you. Tbh I haven't read the article so I'm only responding to your first sentence, since the CSS hyphens thing has been cleared up already.
By the way, CSS hyphens have been my most-wanted feature ever when I was working for a web design agency. So glad to see it gain traction over the years.
There are JS libraries for this, and of course they cause ugly page reflow and/or overhead.
Prime example of what should be in the CSS domain, and such a frequent problem when putting real content into design templates.
To be fair, most of these complaints about functions in JS are because its roots are still a nice prototype-based programming language and the `class` syntax sugar implies class-oriented things that JS doesn't deliver and confuses prototype-oriented features as class-oriented bugs. You can still use them as features, though we are getting close to the point where using them as features is an art form for arcane wizards that will make many, many JS users scream in terror and confusion.
Named functions give you a clear function name which helps in debugging and recursion. For simpler syntax and capturing the surrounding context, arrow functions are handy. You might want to explore MailsAI for organizing your JavaScript code snippets efficiently, it made my workflow smoother.
There is a bit more nuance in using `this` in a named function that wasn't covered. Named functions defined in classes are scoped outside of the class, meaning they are not bound to the class. To use `this` in your named function, you usually have to bind it in the constructor using `this.functionName.bind(this)`
Arrow functions defined within a class are scoped and bound to the class automatically. Hence, arrow functions do not require calling the .bind in constructor, and you can happily use `this` inside arrow functions.
Late binding is also what the above poster is complaining about and they mention the habit some have in class constructors for "early binding" to try to avoid it.
> Somewhat confusingly, we can also give our function expression a name. One that’s separate from the variable name [...] This throws an error. If we can’t use that name, then what’s the point of it? Well, takeyWhiley will show up if we throw an error in our code.
There is another reason: If you give a name to a function expression, the function can directly recurse on itself without the use of combinators. For example:
const factorial = function fact(n) {
if (n == 0)
return 1;
else
return n * fact(n - 1);
};
Anyway, I'm more interested in how this site is being published. I'm on iOS and in vertical format words are cutoff with dashes properly for that format and when I switch to landscape other words are cut off that fit that format.
Is this some simple css attribute I missed completely?
"this" binding depending on the call site never made sense to me. Why do you think it became worse with arrow functions and Function.prototype.bind?
In case I'm not misunderstanding you. Tbh I haven't read the article so I'm only responding to your first sentence, since the CSS hyphens thing has been cleared up already.
By the way, CSS hyphens have been my most-wanted feature ever when I was working for a web design agency. So glad to see it gain traction over the years.
There are JS libraries for this, and of course they cause ugly page reflow and/or overhead.
Prime example of what should be in the CSS domain, and such a frequent problem when putting real content into design templates.
https://developer.mozilla.org/en-US/docs/Web/CSS/hyphens
Arrow functions defined within a class are scoped and bound to the class automatically. Hence, arrow functions do not require calling the .bind in constructor, and you can happily use `this` inside arrow functions.
If you define
then will return "Hello"while
will throw an error.This predates generator functions and classes (which are only syntax sugar AFAIK).
And it seems like a glaring omission giving the submission title.
I'm ashamed though if it's in there and I missed it.
The behavior is called "late binding".
There is another reason: If you give a name to a function expression, the function can directly recurse on itself without the use of combinators. For example:
Dead Comment