Coder Social home page Coder Social logo

paws-on-es6's Introduction

paws-on-es6's People

Contributors

404pnf avatar awalgarg avatar axwalker avatar bracketdash avatar dsathyakumar avatar eddieantonio avatar evert0n avatar hemanth avatar roryrjb avatar simonflk avatar stoeffel avatar vasanthk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

paws-on-es6's Issues

block scope

function aboutme(){
  {
    let wife = 1;
    var gfs = 10;
  }
  console.log(wife,gfs); // 1, undefined.
}

Shouldn't that be:

function aboutme(){
  {
    let wife = 1;
    var gfs = 10;
  }
  console.log(wife,gfs); // undefined, 10
}

as variables with let are block scoped so wife is not visible to console right?

misleading arrow example

I'm not sure the constructor-like example in arrow.js from 844241b is correct.

According to @lukehoban's ES6 Features document cited by the Babel team:

arrows share the same lexical this as their surrounding code

According to @sebmck in a comment before closing babel/babel#730:

Top level this is undefined ES6 modules as they're implicitly strict mode.
Arrow functions inherit the outer this.

The practical upshot of which is that your Person example isn't the constructor you might think it is. Inside the function, this cannot refer to a constructed object. Instead, this is undefined. As Babel transpiles it:

var Person = function (fname, lname, age) {
   undefined.fname = fname;
   undefined.lname = lname;
   undefined.age = age;
   undefined.yo = function () {
      return "Yo! I'm " + undefined.fname + "!";
   }; // `this` reffers to Person.
};

Make Person an ES6 class or ES5 constructor function, and yo works as you expect:

// ES6
class Person {
    constructor(fname, lname, age) {
       this.fname= fname;
       this.lname = lname;
       this.age = age;
       this.yo = () => `Yo! I'm ${this.fname}!`; // `this` refers to Person.
    }
}

// ES5
function Person(fname, lname, age) {
   this.fname= fname;
   this.lname = lname;
   this.age = age;
   this.yo = () => `Yo! I'm ${this.fname}!`; // `this` refers to Person.
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.