0

Can you help me

class Add { constructor(...words) { this.words = words; } } print(){ var str = this.words.join("

quot;); var b = "
quot;+str+"
quot;; console.log(b);// var x = new Add("hehe", "hoho", "haha", "hihi", "huhu"); var y = new Add("this", "is", "awesome"); var z = new Add("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit"); x.print(); y.print(); z.print();

28th Jun 2021, 2:34 PM
Alim Niyazov
Alim Niyazov - avatar
3 Answers
+ 1
Alim Niyazov You have defined function outside the class. That should be inside the class. class Add { constructor(...words) { this.words = words; } print(){ var str = this.words.join("
quot;); var b = "
quot;+str+"
quot;; console.log(b);// } }
28th Jun 2021, 3:31 PM
AÍąJ
AÍąJ - avatar
0
I don't know what my error
28th Jun 2021, 2:35 PM
Alim Niyazov
Alim Niyazov - avatar
0
in addition to declaring the print function as standalone one instead of class (prototype) attached, it lacks closing curly bracket ^^ if you want to declare the function outside of class body, you must use the underlying prototype of constructor (public) function: class Add { /* ... */ } Add.prototype.print = function () { /* ... */ };
28th Jun 2021, 6:53 PM
visph
visph - avatar