The API is somewhat limited in regards to creating Custom Elements. createdCallback
doesn’t take any arguments (and nor do we get to define and use our own constructor). It’d be nice if document.createElement
would take extra arguments to pass to the new Element’s createCallback
. For example:
document.createElement('foo-bar', arg1, arg2, arg3)
Then, arg1
, arg2
, and arg3
would be passed to the element’s createdCallback
, which might look like this:
// ...
createdCallback(arg1, arg2, arg3) {
// do something with the args.
},
// ...
I think this is a simple and much need extension to the API.
The idea here can possibly be combined with https://discourse.wicg.io/t/809. For exampmle, maybe arguments to createdCallback are third and beyond, while the second argument contains attributes:
document.createElement('foo-bar', {
attr1: '1',
attr2, '2'
}, arg1, arg2, arg3)
or something similar. The is-""
attribute needs to be taken into consideration too. Also note that the arguments can be anything, not limited to strings like attributes are.
Any thoughts?