PDA

View Full Version : Resolved hello everyone, i'm new member, everyone help me



michaeltoan016
05-28-2018, 03:36 AM
The following two constructor functions do the same job. But what is the difference between them and which one is more recomended?


// 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();

keyboard
05-29-2018, 12:55 AM
I don't really understand what you're asking sorry.
You only have one constructor (Person)?