-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdifferntWays.js
More file actions
48 lines (37 loc) · 933 Bytes
/
Copy pathdifferntWays.js
File metadata and controls
48 lines (37 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Creating Objects with Constructor
function User(firstName,lastName,age){
this.firstName=firstName;
this.lastName=lastName;
this.age=age;
}
let user=new User('Ram','Sharma',30)
console.log(user)
// Creating Object with Object Literals
let userOther={
firstName:"Jadu",
lastName:"Ghosh",
age:23
}
console.log(userOther)
//Creating Objects with Object.create( )
const userNew={
role:'User',
printDesignation: function(){
console.log(`${this.name} is having salary ${this.salary}`)
}
}
const newUserOther=Object.create(userNew);
newUserOther.name="Jadu Sharma";
newUserOther.salary='30k'
newUserOther.printDesignation()
console.log(newUserOther)
//Using es6 classes
class Vehicle {
constructor(name, maker, engine) {
this.name = name;
this.maker = maker;
this.engine = engine;
}
}
let car1 = new Vehicle('GT', 'BMW', '1998cc');
console.log(car1.name); //GT