4

As mention in document https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions

Arrow functions do not have prototype property

but when I run this on fiddle, why does it gives an object? http://es6console.com/iwyii5vm/

Why it is giving a object?

var Foo = () => {};
console.log(Foo.prototype); 
Bergi
  • 513,640
  • 108
  • 821
  • 1,164
user944513
  • 9,790
  • 23
  • 109
  • 225
  • 1
    es6console automatically passes your code through babel. If you uncheck es2015 under the presets navigation tab, transform your code again, and click run, `undefined` will be logged as expected. – Gerrit0 Dec 21 '16 at 05:52

2 Answers2

7

If you run this code in a native ES6 engine, there will not be a prototype property for arrow functions.

Example of native ES6:

var Foo = () => {};
console.log(Foo.prototype); 

However, if the code is being transpiled to ES5 code, it will not be a true arrow function, and it will have a prototype property.

Example of ES6 being transpiled with Babel:

(Babel is enabled for this snippet)

var Foo = () => {};
console.log(Foo.prototype);

In the case of es6console.com, a transpiler is being used, which is why you are seeing this behavior.

Thank you
  • 107,507
  • 28
  • 191
  • 224
Alexander O'Mara
  • 52,993
  • 16
  • 139
  • 151
  • could you please give online editor where you run this code without transpiled ? – user944513 Dec 21 '16 at 05:52
  • 1
    @user944513 Most will do this by default. JSFiddle and CodePen come to mind. – Alexander O'Mara Dec 21 '16 at 05:53
  • 1
    @user944513 Simply don't select *ES6* as the language. On http://es6console.com/ (whose entire purpose is to provide a babel environment), you'd need un-select the *es2015* preset. – Bergi Dec 21 '16 at 06:11
1

This seems to be an implementation detail of the way es6console implements es6 features. It works correctly in Chrome, which natively supports arrow functions.

enter image description here

bigblind
  • 11,435
  • 13
  • 61
  • 111