46 points · by jrsinclair · 1y ago · 22 comments
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.
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
const o = { a: "Hello", b() { return this.a;} }
then o.a()
will return "Hello"while
const b = o.b; // not a.b ...
b();
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".
I was replying with this because it happens without using the "class" keyword (or "constructor") at all.
Not sure what you mean with the class constructor thing, but that's on me. I still don't understand these properly:
> Named functions defined in classes are scoped outside of the class, meaning they are not bound to the class
> the habit some have in class constructors for "early binding" to try to avoid it.
You mean using sth like
this.a = //...
in the constructor, using arrow functions?I guess I'm missing something here.
That can also be done after the class was declared? The class keyword is only syntax sugar.
Anyway, I might be missing something important here.
That's why I brought up an example using an object literal, which has the prototype
Object.prototype
Try it: const a = {};
console.log(Object.getPrototypeOf(a) === Object.prototype); // logs "true"
These shenanigans are why I sometimes hate JS, but also agree that we should aim to understand the basics first.I love MDN for that.
https://developer.mozilla.org/en-US/docs/Learn_web_developme...
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);
};