Make a Person-freecodecamp algorithm topic

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.