Skip to content

Instantly share code, notes, and snippets.

@HomoEfficio
Created July 22, 2017 13:47
Show Gist options
  • Save HomoEfficio/e90b1166517fa84b799a670638e9b3a4 to your computer and use it in GitHub Desktop.
Save HomoEfficio/e90b1166517fa84b799a670638e9b3a4 to your computer and use it in GitHub Desktop.
usage-of-reduce()-in-javascript
render() {
this._parent.innerHTML = '';
[
[
DOMRenderer.el('input', 'type', 'text'),
DOMRenderer.el('button', 'innerHTML', 'add', 'addEventListener', ['click', e => this.add(new Task(e.target.previousSibling.value))])
].reduce((p, c) => (p.appendChild(c), p), DOMRenderer.el('section')),
DOMRenderer.el('hr'),
this._data.list.reduce((p, c) => (p.appendChild(
[
DOMRenderer.el('h2', '@display', 'inline', 'innerHTML', c.name),
DOMRenderer.el('button', 'innerHTML', 'remove', 'addEventListener', ['click', e => this.remove(c)])
].reduce((p, c) => (p.appendChild(c), p), DOMRenderer.el('section'))
), p), DOMRenderer.el('section'))
].reduce((p, c) => (p.appendChild(c), p), this._parent);
}
@javarouka
Copy link

javarouka commented Jul 22, 2017

코드 보고 있으니 눈이 빙빙 도는군요 @.@;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment