Let's LRun ES6!

- Arrow function -

@iam_keen

Today's story

Context

  • Story Line
  • Start code
  • Self
  • Apply,Call
  • Arrow function
  • Next Movie

Story Line#1

Story Line#2

I'm Your Father

No~~~~~~~~

Start Code

var DarthVaderSays = function(){
  this.name = "Darth Vader";
  this.start = function(){
    console.log(this.name + " says: ----------I'm Your father!----------" );
  }
}
var Action = function(){
  this.name = "Luke Skywalker";
  this.start = function(){
    setTimeout( vader.start, 1000 );
    setTimeout( function(){
      console.log( this.name+" says: ----------No~~~~~~~~~~~~~--");
      console.log( "Starwars Ends----------]");
    }, 1200 );
  }
}

Mental Destruption?

Self

var DarthVaderSays = function(){
  this.name = "Darth Vader";
  self = this;
  this.start = function(){
    console.log(self.name + " says: ----------I'm Your father!----------" );
  }
}
var action = function(){
  this.name = "Luke Skywalker";
  self = this;
  setTimeout( vader.start, 1000 );
  setTimeout( function(){
    console.log( self.name+" says: ----------No~~~~~~~~~~~~~--");
    console.log( "Starwars Ends----------]");
  }, 1200 );
}

좋아요?

Apply, Call

var DarthVaderSays = function(){
  this.name = "Darth Vader";
  this.start = function(){
    console.log(this.name + " says: ----------I'm Your father!----------" );
  }
}
var action = function(){
  this.name = "Luke Skywalker";
  setTimeout( vader.start.call(vader), 1000 );
  setTimeout( function(){
    console.log( this.name+" says: ----------No~~~~~~~~~~~~~--");
    console.log( "Starwars Ends----------]");
  }, 1200 );
}

좋아요?

Arrow

var DarthVaderSays = function(){
  this.name = "Darth Vader";
  this.start = ()=>{
    console.log(this.name + " says: ----------I'm Your father!----------" );
  }
}
var action = {
  name : "Luke Skywalker",
  start : function(){
    setTimeout( vader.start, 1000 );
    setTimeout(()=>{
      console.log( this.name+" says: ----------No~~~~~~~~~~~~~--");
      console.log( "Starwars Ends----------]");
    }, 1200 );
  }
}

Bu뜨

주의하세요

node --harmony somefile.js
babel-node arrow.js

Next Movie

Classes
 

  • module
  • inheritance
  • private member
  • Singleton Pattern

Q&A

https://github.com/ehrudxo/es6_study

Let's LRun ES6! -Arrow Function

By Keen Dev

Let's LRun ES6! -Arrow Function

ES6 Arrow function

  • 967