1. Quick Links
  2. Favorite Javascript Books
  3. ECMAScript 6 (ES 2015)
  4. Basic Language
    1. Prototype
    2. Accessing Object Properties
  5. React
    1. setState

    Quick Links

    • See how ES compiles to javascript: https://babeljs.io/repl/
    • A re-introduction to javascript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Are-introductionto_JavaScript

    Favorite Javascript Books

    • Functional JavaScript (this one is awesome!)
    • Javascript: The Good Parts

    ECMAScript 6 (ES 2015)

    http://www.ecma-international.org/ecma-262/6.0/ECMA-262.pdf

    This version introduces the concept of ES6 modules and the import syntax.

    https://github.com/lukehoban/es6features

    Basic Language

    Prototype

    All objects created from object literals are linked to Object.prototype.

    Accessing Object Properties

    When you try to access a property that does not exist inside an object, javascript gives undefined.

    myobject.dne
    // undefined
    

    If you try to access a property inside undefined, you get a type exception

    myobject.dne.reallydne
    // throws "TypeError"
    

    To guard against this, use &&

    myobject.dne && myobject.dne.reallydne
    // undefined
    

    React

    setState

    Two forms of setState, either just pass an object:

    this.setState({
      something: "changed"
    });
    

    Or pass a function to get access to previous state and props:

    this.setState((prevState, props) => ({
      counter: prevState.counter + props.increment
    }));
    

    setState merges the object passed (or the result from the function passed) into the components state.