Nice finishing touch. I think this is the shortest it could get in this approach with semantic tags.
I just learnt about insertAdjacentHTML & last variable return of arrow functions. (not using widely due to compatibility)
Also, you're absolutely right about XSS & Button. I thought innerText only removing text, keeping the <li></li> :)
So, learnt some new stuff. Thank you!
In your code, the <ol> initially outputs "undefined". So we need to change it to o=b(x,"ol","") there.
Final code:
a=document;b=(d,t,v)=>(d.append(d=a.createElement(t)),d.innerText=v,d);i=b(x=a.body,"input");b(x,"button","+").onclick=_=>b(o,"li",i.value).onclick=(e)=>e.target.style.textDecoration="line-through";o=b(x,"ol","");b(x,"button","X").onclick=_=>o.innerText=""
> last variable return of arrow functions. (not using widely due to compatibility)
It’s not last variable return such as you get in expression-oriented languages like Ruby or Rust; rather, it’s that if what follows the fat arrow is not a curly brace, it’s parsed as an expression, which is made to be the value returned. So `a => { a }` is the void function, but `a => { return a }` and `a => a` are identity functions. Expressed as an approximate grammar, it’s
All forms of arrow functions were introduced at the same time, in ES6 (roughly meaning “everything since but excluding IE”). `a => { return a; }` has identical browser support to `a => a`, so if you use arrow functions you might as well switch to the expression form.
I just learnt about insertAdjacentHTML & last variable return of arrow functions. (not using widely due to compatibility)
Also, you're absolutely right about XSS & Button. I thought innerText only removing text, keeping the <li></li> :)
So, learnt some new stuff. Thank you!
In your code, the <ol> initially outputs "undefined". So we need to change it to o=b(x,"ol","") there.
Final code: a=document;b=(d,t,v)=>(d.append(d=a.createElement(t)),d.innerText=v,d);i=b(x=a.body,"input");b(x,"button","+").onclick=_=>b(o,"li",i.value).onclick=(e)=>e.target.style.textDecoration="line-through";o=b(x,"ol","");b(x,"button","X").onclick=_=>o.innerText=""