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
  • 630,263
  • 148
  • 957
  • 1,375
user944513
  • 12,247
  • 49
  • 168
  • 318
  • 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

8

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.

Mulan
  • 129,518
  • 31
  • 228
  • 259
Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171
  • 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
  • 12,539
  • 14
  • 68
  • 123