با هر سه روش زیر می توان یک شئ person ساخت:
روش اول:
function Person(name, age, job){
this.name = name;
this.age = age;
this.job = job;
this.sayName = function() {
alert(this.name);
}
}
var person = new Person("Saeed", 30, "Software Engineer");
روش دوم:
var person = new Object();
person.name = "Saeed";
person.age = 30;
person.job = "Software Engineer";
person.sayName = function() {
alert(this.name);
};
روش سوم:
var person = {
name: "saeed",
age: 30,
job: "Software Engineer",
sayName: function() {
alert(this.name);
};