This scale in arrow function prototypes

In my understanding, this does not work (this is a contrived example - see RxJS for what I'm actually running):

function Foo() {
  this.name = 'Johnny Cash'
}

Foo.prototype.who = () => {
  console.log(this.name) // undefined
};

var foo = new Foo();

foo.who()

Because it thisdoes not have the correct area. However, this page (the last two lower examples) is used in RxJS documents. How do they run this code?

Wrong code on RxJS page? or do I need to run some kind of Babel plugin (I already tried using babel-require and babel-polyfill with the same effect)

+4
source share
1 answer

The examples on this page are violated.

, , ,

var subcription = emitter.listen('data', data => console.log(`data: ${data}`);

( ).

, - undefined, this .

+2

All Articles