News for hackers. Stuff that matters.
Re:Understanding JavaScript Objects by crooked-v on Friday July 27, 2018 @01:48PM (#17627725)
In JS, everything that's not a primitive is an object, and primitives can themselves be implicitly coerced to objects. That is to say, these are equivalent:

    (new String("abc")).length
    "abc".length
Functions are really just objects that can be invoked as a function, and they can have properties and even prototypes set the same as any other object. This used heavily in React:

    function DivWrapper({ children }) {
      return <div>{children}</div>
    }

    // show a nice name when debugging
    DivWrapper.displayName = 'DivWrapper';

    // verify incoming props when debugging
    DivWrapper.props = {
      children: PropTypes.node
    };
Re:Understanding JavaScript Objects by kevin_thibedeau on Friday July 27, 2018 @04:24PM (#17629036)
The problem is that in the latter case the function object doesn't know what it's name is. This pattern gets unnecessarily abused just to be cool or follow the cargo cult.
Re:Understanding JavaScript Objects by crooked-v on Saturday July 28, 2018 @10:21PM (#17636155)
React adopted displayName to avoid "the function object doesn't know its name" issues, as well as names being mangled by minifiers (or, in the future, stuff like WASM).