嗨,我是初学者学习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);
};
}
提前谢谢!
答案 0 :(得分:2)
命名函数与匿名函数 - 差别不大。当抛出错误时,您将获得具有命名函数的更准确的堆栈跟踪。