News for hackers. Stuff that matters.
Re:Ask HN: What would you change about JavaScript if you could? by maxharris on Thursday September 07, 2017 @11:07PM (#15197630)
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.

Re:Ask HN: What would you change about JavaScript if you could? by hoodoof on Friday September 08, 2017 @12:14AM (#15197808)
I resisted immutability until I really understood that many of my bugs were because of mutation - now I'm a big advocate.
Re:Ask HN: What would you change about JavaScript if you could? by hoodoof on Thursday September 07, 2017 @09:43PM (#15197303)
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.

Re:Ask HN: What would you change about JavaScript if you could? by self_refactor on Wednesday September 13, 2017 @07:07AM (#15237138)
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

Re:Ask HN: What would you change about JavaScript if you could? by wdiamond on Thursday September 07, 2017 @11:11PM (#15197651)
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) { ... } });
Re:Ask HN: What would you change about JavaScript if you could? by uwu on Thursday September 07, 2017 @10:02PM (#15197375)
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;
    }
  };
Re:Ask HN: What would you change about JavaScript if you could? by billconan on Thursday September 07, 2017 @09:55PM (#15197349)
make the syntax more like swift or java, remove the concept of prototype.