Creating your own object part 2

Creating Objects



Once you have an object constructor, you can use the new keyword to create new objects of the same type.
var p1 = new person("John", 42, "green");
var p2 = new person("Amy", 21, "red");

document.write(p1.age); // Outputs 42
document.write(p2.name); // Outputs "Amy"
Try It Yourself

p1 and p2 are now objects of the person type. Their properties are assigned to the corresponding values.

Comments

Popular posts from this blog

String Operators

Introducing object part 3

The math object part 2