-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathobjects-and-methods.js
More file actions
47 lines (41 loc) · 932 Bytes
/
objects-and-methods.js
File metadata and controls
47 lines (41 loc) · 932 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
//first way
var john = {
name: 'John',
lastName: 'Smith',
yearOfBirth: 1990,
job: 'teacher',
isMarried: false,
family: ['Jane', 'Mark', 'Bob'],
calculateAge: function() {
return 2016 - this.yearOfBirth;
}
};
//console.log(john.calculateAge(1970));
console.log(john.calculateAge()); // calculate john age , output 26
var age = john.calculateAge();
john.age = age;
console.log(john);
//---------------------------
//second way
var john = {
name: 'John',
lastName: 'Smith',
yearOfBirth: 1990,
job: 'teacher',
isMarried: false,
family: ['Jane', 'Mark', 'Bob'],
calculateAge: function() {
this.age = 2016 - this.yearOfBirth;
}
};
john.calculateAge();
console.log(john);
//mike calcuate birth
var mike = {
yearOfBirth: 1950,
calculateAge: function() {
this.age = 2016 - this.yearOfBirth;
}
};
mike.calculateAge();
console.log(mike);