3 ms·
Not a problem with named arguments. Too bad that they really screwed that up with ES6: function foo({a = 1, b = 2} = {}) {...} Dart's syntax is a lot eas
by ahoge 12y ago
Not a problem with named arguments.
Too bad that they really screwed that up with ES6:
function foo({a = 1, b = 2} = {}) {...}
Dart's syntax is a lot easier to remember:
foo({a: 1, b: 2}) {...}
Another very important detail: ES6's syntax is not declarative. You aren't restricted to "compile-time" constants and you can do all kinds of bogus stuff there.
function foo({a = 1, b = 2, c} = {c: 3}) {
console.log(a, b, c);
}
foo(); // 1 2 3
foo({a: 'a'}); // a 2 undefined
foo({c: 'c'}); // 1 2 c
But wait! There is more!
function foo({length = 2} = 'foobar') {
console.log(length);
}
foo(); // 6
foo({length: 0}); // 0
foo({x: 'x'}); // 2
Just look at that! Those short Hello World examples are already super confusing brain teasers.
I really don't understand why they prioritized this kind of excessive flexibility over tooling. Now you can put entire programs into a function's signature. Why would anyone want that?
- tel 12y agoIt's still a problem with named parameters if the name doesn't dramatically break the symmetry between "true" and "false". Even if it does, booleans are still dangerous because they're harder to check statically.
- dllthomas 12y agoWhich isn't to say named parameters don't help a bunch over boolean positional parameters!