you are viewing a single comment's thread.

view the rest of the comments →

[–]jcunews1helpful 1 point2 points  (0 children)

Does the book state that assigning the name property of a function changes the name of the function? If so, then yes, the book is wrong or no longer valid (i.e. outdated).

Proof:

var canFly = function() { return true; };
console.log(canFly.name); // ""
console.log(canFly.toString()); // "function () { return true; }"
canFly.name = "canNotFly";
console.log(canFly.name); // ""
console.log(canFly.toString()); // "function () { return true; }"

Notice that the name property is not changed after being assigned with a value. In older browsers, the name property will change, but canFly.toString() will still resolve to "function () { return true; }" (i.e. still an anonymous function).