码迷,mamicode.com
首页 > 编程语言 > 详细

[Javascript] MetaProgramming: function name

时间:2016-06-13 18:58:39      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

Each function should have a ‘name‘ property. It can be anonymous, empty, the same as function name, or class name.

 

For example:

const foo = function(){}
console.log(foo.name); //foo

 

function(){ .. });                 // name:
(function*(){ .. });                // name:
window.foo = function(){ .. };      // name:

class Awesome {
    constructor() { .. }            // name: Awesome
    funny() { .. }                  // name: funny
}
var c = class Awesome { .. };       // name: Awesome

var o = {
    foo() { .. },                   // name: foo
    *bar() { .. },                  // name: bar
    baz: () => { .. },              // name: baz
    bam: function(){ .. },          // name: bam
    get qux() { .. },               // name: get qux
    set fuz() { .. },               // name: set fuz
    ["b" + "iz"]:
        function(){ .. },           // name: biz
    [Symbol( "buz" )]:
        function(){ .. }            // name: [buz]
};

export default function() { .. }    // name: default

var y = new Function();             // name: anonymous
var GeneratorFunction =
    function*(){}.__proto__.constructor;
var z = new GeneratorFunction();    // name: anonymous

 

[Javascript] MetaProgramming: function name

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5581343.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!