+ 1

How to call object properties without their names

Hello, i am currently doing the last practice in javascript section. I was stumped at the part where i have to call object properties. I can only call them by names, which means using the static method for other object is not possible? How can i do this? How do i call multiple object's properties with a single caller that applies globally to all objects? (Cuz im using a function) Thanks in advance https://code.sololearn.com/W8MnJJ1JcP1C/?ref=app

15th Oct 2022, 1:14 AM
Hizand
Hizand - avatar
1 Answer
+ 1
If I read the task correctly you aren't supposed to add a static method, just a regular one :) And implement the function just for single objects. class Add { constructor(...){ ... } print () { // use this.words here :) } } const a = new Add(...); a.print(); What you are describing (get all objects ever made and access their properties) is not really possible, since objects get made and destroyed all the time and javascript doesn't really have a way to track that. If you want less code duplication you could for (const obj of [x,y,z]) obj.print();
15th Oct 2022, 1:44 AM
Schindlabua
Schindlabua - avatar