I'm on "Introducing ES2015" course of Treehouse and the teacher shows this code to illustrate the arrow functions but here he instantiates the function as a class. Can anybody tell me how is it possible?
What I learned about objects is that you need to create a class before to instantiate it or create a literal object which is not this case.
'use strict'; var Person = function(data) { for (var key in data) { this[key] = data[key]; } this.getKeys = () => { return Object.keys(this); } } var Alena = new Person({ name: 'Alena', role: 'Teacher' }); console.log('Alena\s Keys: ', Alena.getKeys()); // 'this' refers to 'Alena' var getKeys = Alena.getKeys; console.log(getKeys()); Everything works but I don't know why.
classjust creates a function ... then I do confuse you even more right? ;)Classdoesn't really exist in javascript. The transpilation ofclass Person {}in ES will be what your teacher has writen :)