Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
As you saw with the Person()
constructor, we can make our own constructor functions, from which we can
produce not just one but multiple custom
objects.
Below, I present the familiar Person() constructor function:
<!DOCTYPE html><html lang="en"><body><script> var Person = function(living, age, gender) { this.living = living; this.age = age; this.gender = gender; this.getGender = function() {return this.gender;}; }; var cody = new Person(true, 33, 'male'); console.log(cody); // logs Object {living=true, age=33, gender="male", ...} var lisa = new Person(true, 34, 'female'); console.log(lisa); // logs Object {living=true, age=34, gender="female", ...} </script></body></html>