Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

different.js - Forward JS 2014

different.js - Forward JS 2014

video available here: https://thenewcircle.com/s/post/1656/differentjs_video_forward_js

Let’s expand our programming minds by thinking about how we can use javascript in experimental and unusual ways. Can we write javascript without ever using the ‘this’ keyword? Would we want to? Can we write javascript without sharing mutable state? Would we want to?
You might not leave this talk with code examples that you’ll apply to your production code tomorrow, but you’ll leave with a different perspective and a new way of thinking about how JavaScript can work.

Pete Hodgson

July 25, 2014
Tweet

More Decks by Pete Hodgson

Other Decks in Programming

Transcript

  1. function myClass(message) { this.message = message; var self = this;

    $('button').click(function(){ self.onClick(); }); } this!!!! @ph1
  2. A PERSON @ph1 george = new Person() ! george.eatCake() //

    om nom nom nom ! george.stillHungry() // returns true or false
  3. if( george.stillHungry() ){ // blah } george.eatCake(); { … }

    var george = new Person(); { … } @ph1 { … }
  4. if( george.stillHungry() ){ // blah } george.eatCake(); { … }

    var george = new Person(); { … } @ph1 { … }
  5. function Person(){ this.cakesEaten = 0; } ! Person.prototype.eatCake = function(){

    this.cakesEaten += 1; }; ! Person.prototype.stillHungry = function(){ return this.cakesEaten < 3; }; @ph1 WITH PROTOTYPES / THIS
  6. function Person(){ this.cakesEaten = 0; } ! Person.prototype.eatCake = function(){

    this.cakesEaten += 1; }; ! Person.prototype.stillHungry = function(){ return this.cakesEaten < 3; }; @ph1 WITH PROTOTYPES / THIS
  7. function createPerson(){ var cakesEaten = 0; return { eatCake: function(){

    cakesEaten += 1; }, stillHungry: function(){ return cakesEaten < 3; } }; } function } ! Person }; ! Person }; @ph1 WITH CLOSURES
  8. LEVEL UP ▫︎no return values (yes, really!) ▫︎only 1 parameter

    ▫︎all functions less than 5 lines long ▫︎test-first everything ▫︎no tests ▫︎immutable objects ▫︎no “methods” (functions on objects) ▫︎functional reactive 19 @ph1