-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathprogram.js
More file actions
74 lines (60 loc) · 1.33 KB
/
Copy pathprogram.js
File metadata and controls
74 lines (60 loc) · 1.33 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
63
64
65
66
67
68
69
70
71
72
73
74
`Constructor Functions
* Create multiple objects with same body using a constructor function`
function Person(name, age){
this.name = name;
this.age = age;
this.greeting = function() {
console.log(`hi ${name}`);
}
}
// defining methods outside the constructor
Person.hey = function() {console.log("hello")};
Person.hey();
Person.prototype.welcome = function() {
console.log(`welcom ${this.name}`);
}
let obj = new Person('abc', 21);
obj.gender = function(gen) {
console.log(this.name, gen);
};
obj.gender("male");
console.log(obj);
console.log(obj["name"]);
console.log(obj.age);
obj.greeting();
obj.welcome();
function Human(name, age, gender) {
Person.call(this, name, age);
this.gender = gender;
this.greet = function() {
console.log(`hello ${this.name}`);
}
}
let obj2 = new Human('abc', 21, "male");
console.log(obj);
let obj3 = new Human('abcd', 22, "female");
console.log(obj2);
let test1 = {
string: "hey",
}
let test2 = {
number: 50,
}
// copying objects
Object.assign(test1, test2);
test2.number = 60;
console.log(test1);
console.log(test2);
console.log('test' in test1);
// obj2.greet();
// obj2.greeting();
// obj3.greeting();
// console.log("name" in obj);
function a() {
console.log("12");
return function() {
return 1;
}
}
let b = a();
console.log(b);