私は2つのファイルindex.jsとactor.jsを持っています
Index.js
const {Actors} = import("./Actors");
const act1= new Actors({
name: 'Tony Stark',
alias: 'Iron Man',
gender: 'man',
age: 38,
powers: ["intelligence", "durability", "magnetism"]
})
const act2= new Actors({
name: 'Natasha Romanoff',
alias: 'Black Widow',
gender: 'woman',
age: 35,
powers: ["agility", "martial arts"]
})
const examine = (avenger) => {
console.count('Actors');
console.group('*** Actors introduced ***');
console.log(avenger.toString());
console.groupEnd();
console.group('*** Actors called ***');
console.log(avenger());
console.groupEnd();
console.group('*** Actors\'s internals ***');
console.log(avenger, '\n');
console.groupEnd();
}
examine(act1);
examine(act2);
Actors.js
class Actors {
constructor(obj) {
this.name = obj.name;
this.age = obj.age;
this.alias = obj.alias;
this.gender = obj.gender;
this.powers = obj.powers;
}
toString() {
return `name:${this.name} \ngender:${this.gender}\nage:${this.age}`;
}
avenger() {
let str = '';
this.powers.forEach(element => {
str += `$element \n`;
});
return `${this.alias}` + str;
}
}
module.exports.Actors= Actors;
Actors
関数呼び出しavenger()
が 機能しconsole.log(avenger());
、次の期待される結果が得られるように、 class を変更するにはどうすればよいですか。
IRON MAN
intelligence
durability
magnetism