fork download
  1. class Add {
  2. constructor(...words) {
  3. this.words = words;
  4. }
  5.  
  6. print() {
  7. var s = "$";
  8. if (this.words.length > 0) {
  9. this.words.map(w => {s += w + "$"});
  10. } else {
  11. s += "$";
  12. }
  13. console.log(s);
  14. }
  15. }
  16.  
  17. var x = new Add("hehe", "hoho", "haha", "hihi", "huhu");
  18. var y = new Add("this", "is", "awesome");
  19. var z = new Add("lorem", "ipsum", "dolor", "sit", "amet", ",", "consectetur", "adipiscing", "elit");
  20. var a = new Add();
  21. x.print();
  22. y.print();
  23. z.print();
  24. a.print();
Success #stdin #stdout 0.02s 17340KB
stdin
Standard input is empty
stdout
$hehe$hoho$haha$hihi$huhu$
$this$is$awesome$
$lorem$ipsum$dolor$sit$amet$,$consectetur$adipiscing$elit$
$$