js make new object code example
Example 1: creating an object javascript
let obj = {
name:"value",
num: 123,
foo: function(){}
}
Example 2: how to create object js
function person(fname, lname, age, eyecolor){
this.firstname = fname;
this.lastname = lname;
this.age = age;
this.eyecolor = eyecolor;
}
myFather = new person("John", "Doe", 50, "blue");
document.write(myFather.firstname + " is " + myFather.age + " years old.");
Example 3: javascript construct new object
person = new Object();
Example 4: how to create a object in javascript
var a = {
name: "aakash",
age:30
}
Example 5: create object javascript
let voleur = {
action : () =>console.log ('Coup de dague fatal') ,
crie : ('pour la horde!!!!') ,
coupfatal :()=> console.log ('coup dans le dos')
}
voleur.action() ;
voleur.coupfatal() ;
console.log(voleur.crie) ;