-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
62 lines (48 loc) · 1.19 KB
/
script.js
File metadata and controls
62 lines (48 loc) · 1.19 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Vanilla JavaScript
function Person(name, age) {
this.name = name;
this.age = age;
}
function Cricketer(name, age, type, country) {
Person.call(this)
this.name = name;
this.age = age;
this.type = type;
this.country = country;
}
Person.prototype={
eat: function(){
console.log(`${this.name} is eating`);
}
}
Cricketer.prototype.play = function(){
console.log(`${this.name} is playing`);
}
Cricketer.prototype = Object.create(Person.prototype);
Cricketer.prototype.constructor = Cricketer;
let sakib = new Cricketer('sakib', 34, 'allrounder', 'Bangladesh',);
console.log(sakib.eat());
// class based JavaScript
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
eat() {
console.log(`${this.name} is eating`);
}
}
class Cricketer extends Person {
constructor(name, age, type, country) {
super(name,age)
this.name = name;
this.age = age;
this.type = type;
this.country = country;
}
play() {
console.log(`${this.name} is playing`);
}
}
let sakib = new Cricketer('sakib', 34, 'allrounder', 'Bangladesh',);
console.log(sakib.eat());