与构造函数中的函数名称有何不同?

时间:2016-07-15 08:22:15

标签: javascript constructor

嗨,我是初学者学习javascript。以下2个构造函数有什么区别?

function Animal(name) {
        this.name = name;
        this.walk = function walk(destination) { //here function has name 'walk'
                console.log(this.name,'is walking to',destination);
        };
}

function Animal(name) {
        this.name = name;
        this.walk = function (destination) { // but no function name
                console.log(this.name,'is walking to',destination);
        };
}

提前谢谢!

1 个答案:

答案 0 :(得分:2)

命名函数与匿名函数 - 差别不大。当抛出错误时,您将获得具有命名函数的更准确的堆栈跟踪。

相关问题