Hi all,
I am referring to this challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person
Here my code:
var Person = function(firstAndLast) {
// Complete the method below and implement the others similarly
this.getFullName = function() {
return firstAndLast;
};
this.getFirstName = function(){
return firstAndLast.split(' ').shift();
}
this.getLastName = function(){
return firstAndLast.split(' ').pop();
}
this.setFirstName = (firstName) => {
let lastName = firstAndLast.split(' ')[1];
firstAndLast = firstName.concat(' '.concat(lastName));
}
this.setLastName = (lastName) => {
let firstName = firstAndLast.split(' ')[0];
firstAndLast = firstName.concat(' '.concat(lastName));
}
this.setFullName = (newFullName) => {
firstAndLast = newFullName;
}
return firstAndLast;
};
Here my questions:
-
After having instantiate a new Person object the
firstAndLast
argument stores the full name of our new object right? So given that, then there is always a kind offirstAndLast
variable per instantiated Person object? -
It is possible to access
firstAndLast
from outside the object? -
As I did in my code I’m able to mutate
firstAndLast
even though it was not saved in another internal object variable like:
this.firstAndLast = firstAndLast;
- Although I haven’t save
firstAndLast
in another variable as shown above I usefirstAndLast
all over as an instance specific variable. How does it work?
I hope I used the correct words to formulate my questions.
As always thanks in advanced for any advice.
Regards,