问题描述
如文件中所述 https://developer.mozilla.org/en/docs/Web/JavaScript/参考/功能/箭头功能
箭头功能没有原型属性
但是当我在小提琴上运行它时,为什么会给出object
? http://es6console.com/iwyii5vm/
but when I run this on fiddle, why does it gives an object
?http://es6console.com/iwyii5vm/
为什么要给对象?
var Foo = () => {};
console.log(Foo.prototype);
推荐答案
如果在本机ES6引擎中运行此代码,则箭头功能将没有prototype
属性.
If you run this code in a native ES6 engine, there will not be a prototype
property for arrow functions.
var Foo = () => {};
console.log(Foo.prototype);
但是,如果将代码转换为ES5代码,它将不是真正的箭头函数,而是具有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.
(此代码段已启用Babel)
(Babel is enabled for this snippet)
var Foo = () => {};
console.log(Foo.prototype);
对于es6console.com
,正在使用编译器,这就是为什么您看到此行为的原因.
In the case of es6console.com
, a transpiler is being used, which is why you are seeing this behavior.
这篇关于为什么我的arrow函数具有原型属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!