A new instance of the object has been created and four properties have been added to it:
person=New Object (); // do not varperson.firstname= "Bill";p erson.lastname= "Gates";p erson.age=56; Person.eyecolor= "Blue";
Alternative code:
var person={firstname: "John", LastName: "Doe", Age:50,eyecolor: "Blue"};
Using the Object Builder:
function Person (Firstname,lastname,age,eyecolor) {this. firstname=FirstName; this. lastname=LastName; this. age= age; this. eyecolor=Eyecolor;} var tercher=New person ("Bill", "Gates", "page", "Blue");
Methods for defining objects inside the constructor function:
function Person (Firstname,lastname,age,eyecolor) {this. firstname=FirstName; this. lastname=LastName; this. age= age; this. eyecolor=Eyecolor; this. changename=changename; function ChangeName (name) {this. lastname=name;}}
Call:
Mymother.changename ("Ballmer");
Iterate through the properties of an object:
<! DOCTYPE html>function myFunction () {var x; var txt= ""; var person={fname: "Bill", lname: "Gates", age:56 for the person ) {txt= TXT + person[x];} document.getElementById ("Demo"). innerhtml=txt;} </script></body>
Results: BILLGATES56
Reference: JS object creation, JS Create class and Object
js--Create object