What is the difference between normal function declaration and inside return block function declaration in Javascript.
Below code normal function name : updatename, inside function name : 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");
newthe function should not return anything. Thenewkeyword will return the function'sthis. I repeat: thenewkeyword returns an object, not the constructor.