1
正则函数声明和Javascript中的内部返回块函数声明有什么区别?Javascript中的正常函数声明和内部返回块函数声明的区别
下面的代码正常功能名称:updatename,内部函数名称:changeName
function person(firstName,lastName,age,eyeColor) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.eyeColor = eyeColor;
this.updatename = function (name) {
this.lastName = name;
}
return {
'changeName' : function (name) {
this.lastName = name;
}
};
}
var myMother = new person("Sally","Rally",48,"green");
console.dir(myMother);
console.log(typeof(myMother.changeName));
console.log(typeof(myMother.updatename));
myMother.changeName("Doe");
这不是一个返回块。这是一个对象文字。 – slebetman
如果注释掉正常函数并执行上面的代码typeof(myMother.changeName)返回函数。 – balamuruganv
他们都是功能。从语言的角度来看没有区别。他们来自不同的范围,但是就是这样。 – vlaz