Skip to content

Commit 3b4e7c5

Browse files
committed
[EX-15.10/st-compl] adding-individual-methods
Adding individual meth's to obj, nested obj's. Working with own "this". Worth noting: - different "calls" of the same methods. FS-dev: B-3 / JS basic
1 parent 8a66385 commit 3b4e7c5

File tree

1 file changed

+29
-0
lines changed
  • full-stack-dev/3-js-basic/15-scope-chain-this/15-10-ex-adding-individual-methods

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Нужно написать методы, позволяющие выводить имена различных сущностей компании (т.е. отдельно, для имени компании, для владельцев, для сотрудники) с использованием `this` для обращения к соответствующему/вложенному объекту.
2+
// - точнее нужно правильно/потом организовать вызовы методов, что бы для всех/всё корректно выводилось!
3+
4+
'use strict';
5+
6+
const company = {
7+
name: 'LLC MDev',
8+
employees: [
9+
{
10+
name: 'Ann',
11+
getName() {
12+
return this.name;
13+
},
14+
},
15+
],
16+
ceo: {
17+
name: 'Sergey',
18+
getName() {
19+
return this.name;
20+
},
21+
},
22+
getName() {
23+
return this.name;
24+
},
25+
};
26+
27+
console.log(company.getName()); // "LLC MDev"
28+
console.log(company.ceo.getName()); // "Sergey"
29+
console.log(company.employees.map((employee) => employee.getName())); // [ 'Ann' ]

0 commit comments

Comments
 (0)