JavaScript: Defining function inside function -
in w3schools example, not getting how changename
works:
function person(firstname, lastname, age, eyecolor) { this.firstname = firstname; this.lastname = lastname; this.age = age; this.eyecolor = eyecolor; this.changename = changename; function changename(name) { this.lastname = name; } } mymother = new person("sally", "rally", 48, "green"); mymother.changename("doe"); document.write(mymother.lastname);
why have this.changename=changename
, , function definition changename
?
it defining method changename
person
objects - in sort of round-about way, equivalent (and better) way is:
this.changename = function(name) { this.lastname = name; }
(hence 'please not use w3school')
Comments
Post a Comment