John
0
Q:

creating an object javascript

let obj = {
// fields
  name:"value",
  num: 123,
//methods
  foo: function(){}
  
}
9
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.");
2
const object = {
  something: "something";
}
2

var car = {type:"Fiat", model:"500", color:"white"};
 
3
class ObjectLayout {
	constructor() {
    	this.firstName = "Larry"; //property
    }
  
  	sayHi() { // Method
    	return `Hello from ${this.firstName}`;
    }
}

const object = new ObjectLayout();
// object.firstName is Larry;
// object.sayHi() gives "Hello from Larry"
0
var about = {
  name:"lanitoman",
  age:1023,
  isHeProgrammer:true
}
0
var a = {
name: "aakash",
  age:30
}
0
let bike = {   name: 'SuperSport',    maker:'Ducati',    start: function() {       console.log('Starting the engine...');   }};bike.start();   //Output: Starting the engine.../* Adding method stop() later to the object */bike.stop = function() {    console.log('Applying Brake...');  }bike.stop();    //Output: Applying Brake...
1
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) ;
0

New to Communities?

Join the community