Javascript newbie here, this block of code doesn't make sense.
function Warrior(n){
var name = n;
this.name = function(n){
if( n ) name=n;
return name;
}
}
Warrior.prototype.toString = function(){
return "Hi! my name's "+this.name();
}
Converting the instance of Warrior to a string works, calling the name function works with or without params... why, shouldn't var name
die right after the class is constructed? Why does it seem to linger? And if vars stay, then why use this
?