函數(shù)的name屬性返回該函數(shù)的函數(shù)名。
非匿名函數(shù)
function foo(){}
foo.name // "foo"
匿名函數(shù)
var foo = function(){}
es5: foo.name // ""
es6: foo.name // "foo"
非匿名函數(shù)賦值給變量
const foo = function bar(){}
foo.name // "bar" 權(quán)重更高
bind返回的函數(shù),name屬性值會加bound前綴
function foo(){}
foo.bind({}).name // "bound foo"
Function構(gòu)造函數(shù)返回
(new Function()).name // "anonymous"
注意:name屬性只是協(xié)助調(diào)試的額外信息,并不能通過name屬性獲取對函數(shù)的引用
原文地址:http://omeme.me/2017/08/15/shen-ru-li-jie-es6-han-shu-zhi-nameshu-xing/,長期更新es6系列。