Results 1 to 2 of 2

Thread: hello everyone, i'm new member, everyone help me

  1. #1
    Join Date
    May 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default hello everyone, i'm new member, everyone help me

    The following two constructor functions do the same job. But what is the difference between them and which one is more recomended?
    Code:
    // we define a constructor for Person objects
    function Person(name, age, isDeveloper) {
        this.name = name;
        this.age = age;
        this.isDeveloper = isDeveloper || false;
    
        this.writesCode = function() {
          console.log(this.isDeveloper? "This person does write code" : "This person does not write code");
        }
    }
    
    var person1 = new Person("Bob", 38, true);
    var person2 = new Person("Alice", 32);
    
    // prints out: This person does write code
    person1.writesCode();
    // prints out: this person does not write code
    person2.writesCode();
    Last edited by keyboard; 05-29-2018 at 12:54 AM. Reason: Format: Code Tags

  2. #2
    Join Date
    Mar 2011
    Posts
    1,653
    Thanks
    59
    Thanked 101 Times in 99 Posts
    Blog Entries
    4

    Default

    I don't really understand what you're asking sorry.
    You only have one constructor (Person)?

Similar Threads

  1. Hello new member!
    By samuel joff in forum The lounge
    Replies: 4
    Last Post: 06-07-2016, 12:51 PM
  2. New member!
    By Blake in forum The lounge
    Replies: 18
    Last Post: 03-05-2007, 03:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •