Make a person
1. Requirements
- Constructs an object using the method given below: Getfirstname (), Getlastname (), Getfullname (), Setfirstname (first), Setlastname (last), and Setfullname (Firstandlast).
- All methods that have parameters accept only one string parameter.
- All methods interact with the entity object only.
2. Ideas
- Based on the relevant links, an object is constructed using the method given in the topic. Constructing objects
3. Code
var Person = function(firstAndLast) { var firstName=firstAndLast.split(' ')[0]; var lastName=firstAndLast.split(' ')[1]; this.getFirstName=function(){ return firstName; }; this.getLastName=function(){ return lastName; }; this.getFullName=function(){ return firstName+' '+lastName; }; this.setFirstName=function(first){ firstName=first; }; this.setLastName=function(last){ lastName=last; }; this.setFullName=function(firstAndLast){ firstName=firstAndLast.split(' ')[0]; lastName=firstAndLast.split(' ')[1]; }; return firstAndLast;};var bob = new Person('Bob Ross');bob.getFullName();
4. RELATED LINKS
- Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Closures
- Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Details_of_the_Object_Model
Make a Person-freecodecamp algorithm topic