I have created a GPT app in the store, that outputs JavaScript Web Components.
Since GPT is trained on old Web Components GPT is biased in its output.
For example, because older blogs and even MDN say "use super()
first in the constructor", GPT outputs:
constructor() {
super();
const createElement = (tag, props = {}) => Object.assign(document.createElement(tag), props);
let shadow = this.attachShadow({ mode: 'open' });
shadow.append( createElement( "style", innerHTML = `` ));
}
But uou can use JavaScript before super()
because it sets and returns the this
scope. I want it to write:
constructor() {
const createElement = (tag, props = {}) => Object.assign(document.createElement(tag), props);
super()
.attachShadow({ mode: 'open' })
.append( createElement( "style", innerHTML = `` ));
}
These are my instructions (related to this part of the code):
* Include a `createElement(tag, props={})=>Object.assign(document.createElement(tag),props)` function.
* Prefer using the createElement function over `innerHTML`.
* Always add the createElement function as first statement in the constructor.
* Limit to one `createElement("style")` call.
* Avoid using `this.shadowRoot.querySelector` to access elements created with `createElement`.
* Store elements created with `createElement` as properties of `this` within the `.append` method.
* Chain `.attachShadow({mode:"open"}).append()` or `.attachShadow({mode:"open"}).innerHTML`.
* Chain `super().innerHTML`.
How can I force GPT to output JavaScript in my preferred pattern?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/QmTaLjb
Comments
Post a Comment