-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_objects.js
More file actions
92 lines (76 loc) · 2.2 KB
/
06_objects.js
File metadata and controls
92 lines (76 loc) · 2.2 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Объекты
const person = {
nameA: 'Sergey',
age: 20,
isProgrammer: true,
languages: ['ru', 'en', 'de'],
// 'complex key': 'Complex value',
// ['key_' + (1 + 3)]: 'Computed key', // key_4
greet() {
console.log('Greetings from Armenia!')
},
info() {
// console.log('this:', this)
console.info('Информация про человека по имени:', this.nameA)
}
}
// console.log(person.nameA)
// const ageKey = 'age'
// console.log(person[ageKey])
// console.log(person['complex key'])
// console.log(person)
// person.greet()
// person.age++
// person.languages.push('am')
// // person['key_4'] = undefined
// delete person['key_4']
// console.log(person)
// console.log(person['key_4'])
// const name = person.nameA
// const age = person.age
// const languages = person.languages
// const {nameA, age: personAge = 10, languages} = person
// console.log(person)
// for (let key in person) {
// if (person.hasOwnProperty(key)) {
// console.log('key:', key)
// console.log('value:', person[key])
// }
// }
// Object.keys(person).forEach((key) => {
// console.log('key:', key)
// console.log('value:', person[key])
// })
// Context
// person.info()
const logger = {
keys() {
console.log('Object Keys: ', Object.keys(this))
},
keysAndValues() {
// Object.keys(this).forEach((key) => {
// console.log(`"${key}": ${this[key]};`)
// })
// const self = this
Object.keys(this).forEach(function(key) {
console.log(`"${key}": ${this[key]};`)
}.bind(this))
},
withParams(top = false, between = false, bottom = false) {
if (top) {
console.log('---- Start ----')
}
Object.keys(this).forEach((key, index, array) => {
console.log(`"${key}": ${this[key]};`)
if (between && index !== array.length - 1) {
console.log('--------------')
}
})
if (bottom) {
console.log('---- End ----')
}
}
}
// logger.keysAndValues.call(person)
logger.withParams.call(person, true, true, true)
logger.withParams.apply(person, [true, true, true])