|
|
|
|
|
by tnzm
1755 days ago
|
|
So, this, but with more steps? function Foo () {
var x = 1 // "static initialization block"
return {
y: 2,
z: function () { return x + y }
}
}
const foo = Foo()
There's been exactly zero need for the "class" keyword, "constructor()", or that new "#private" thing.There is one flaw in the design of the language which opens the door to all this nonsense; that's having to write "foo.method.bind(foo)" instead of just "foo.method" when passing "method" as a callback, in order to preserve the value of "this". Although in the example above this is not a problem, as you can write functional code that passes the context explicitly without needing "this". Another thing I wish JavaScript had kept was the "with" statement. |
|
Consider the following:
Does this mean:(1) a.b.c.d = e
(2) d = a.b.c.e
(3) something else
(4) it's impossible to tell?
Correct answer: (4) it's impossible to tell!
One of the worst things about programming is looking at someone else's code (or worse, one's own code) and thinking "WTF did they mean by that?". And that's why I don't like the with statement.