
Ask HN: What would you change about JavaScript if you could? - hoodoof
Ideally replies with a minimum of snark.<p>&quot;Change the syntax to Python &lt;or your favorite language&gt;&quot; isn&#x27;t the sort of reply that would be helpful in this thread.
======
maxharris
I 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
I resisted immutability until I really understood that many of my bugs were
because of mutation - now I'm a big advocate.

------
hoodoof
I'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.

------
self_refactor
Remove 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

------
wdiamond
I 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) { ... } });

------
uwu
not 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;
        }
      };

------
billconan
make the syntax more like swift or java, remove the concept of prototype.

