Advertisement
avr39-ripe

extendedArrayClass

Apr 9th, 2020
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ExtendedArray extends Array
  2. {
  3.     constructor(separator = ':', tag = 'li',...args)
  4.     {
  5.         super(...args);
  6.         this._separator = separator;
  7.         this._tag = tag;
  8.     }
  9.     toString(separator = this._separator)
  10.     {
  11.         this._separator = separator;
  12.         return this.join(this._separator);
  13.     }
  14.     toHtml(tag = this._tag)
  15.     {
  16.         this._tag = tag;
  17.         let base = '';
  18.         base = this.reduce((prev,it)=>{ return `${prev}<${this._tag}>${it}</${this._tag}>`;},base)
  19.         base = this._tag = 'li' ? `<ul>${base}</ul>` : base;
  20.         return base;
  21.     }
  22.     render()
  23.     {
  24.         document.write(this.toHtml());
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement