I noticed that ParentNode.append()
returns undefined
, but if it returned this
, then it would be possible to write stuff like this:
document.body.append(
document.createElement('div').append(
document.createElement('span').append(
'hello'
),
new MyElement().append(
new MyOtherElement().append(
document.createElement( 'div' ).append(
document.createElement('select').append(
document.createElement('option').append('option1'),
document.createElement('option').append('option2'),
document.createElement('option').append('option3')
)
)
)
)
)
)
which is somewhat “declarative”. Does any native API exist like that? It would also be easy to map JSX
to that.
I know we can create these APIs ourselves. Just wondering about native options.