4 ms·
Ask HN: What would you change about JavaScript if you could?
Ideally replies with a minimum of snark.
"Change the syntax to Python <or your favorite language>" isn't the sort of reply that would be helpful in this thread.
- hoodoof 9y agoI'd REALLY like to be able to query deeply nested object attributes without having to test every single level of the object hierarchy to find if the attribute exists. Function level scope would be great too - it would be good to conditionally declare and set variables in a function without needing to pre-declare the variable outside the condition test.
- RodericDay 9y agoYou can try/catch.
- billconan 9y agomake the syntax more like swift or java, remove the concept of prototype.
- uwu 9y agonot a change to an existing thing but i have a feature idea: variables that aren't initialized until the first time they're accessed textarea.onkeydown = event => { // doesn't get the properties until they're accessed const get {selectionStart, selectionEnd, value} = textarea; // doesn't actually call .slice yet const get selectedText = value.slice(selectionStart, selectionEnd); // ... if (event.key === "Enter") { // initializes selectedText console.log("selected text: " + selectedText); // uses the same value, doesn't reinitialize it selectedText; } };
- maxharris 9y agoI wish JavaScript had built-in immutable data structures. Immutable.js is interesting, but difficult to bring into a project because it's difficult to get buy-in from everyone involved. I also wish JavaScript were generally better at functional programming - I'd love to see a keyword that ensures that no form of mutation is possible within a given scope.
- hoodoof 9y agoI resisted immutability until I really understood that many of my bugs were because of mutation - now I'm a big advocate.
- wdiamond 9y agoI wish javascript could handle operator overload. not only basic operator, also any custom. something like: objectClass.prototype.operator like = function(a,b) {...} objectClass3 = objectClass1 like objectClass2; Object.defineOperator(objectClass.prototype,"like",{ priority: 10, type: "binary", callback : function(a,b) { ... } });
- self_refactor 9y agoRemove the need of parentheses on if else statements if foo === 'FOO' && bar > 7 { console.log(bar) return true }else if typeof foo === 'string'{ return false } return null