JavaScript Examples

Andreas Ahlgren's examples from the lecture on JavaScript. 

How to add traceur to your webpage and be able to write ES6: 

<!DOCTYPE html>
<html>
  ...
  <body>
    <h1 id="message"></h1>
    <script src="https://google.github.io/traceur-compiler/bin/traceur.js"></script>
    <script src="https://google.github.io/traceur-compiler/src/bootstrap.js"></script>
    <script type="module">
      class Greeter {
        constructor(message) {
          this.message = message;
        }

        greet() {
          let element = document.querySelector('#message');
          element.innerHTML = this.message;
        }
      };

      let greeter = new Greeter('Hello, world!');
      greeter.greet();
    </script>
    ...
  </body>
</html>


The bold part is the important bit. :) 


For the examples I used during the lecture - please see:

http://codepen.io/screener/pens/public/

and:

http://jsfiddle.net/Lwotqb4j/2/

for callbacks

Published Oct. 5, 2015 3:21 PM