Skip to content
Snippets Groups Projects
Commit 4009e6bd authored by Thomas Fritsch's avatar Thomas Fritsch
Browse files

fin B.3. + B.4. héritage

parent e0902df7
No related branches found
No related tags found
No related merge requests found
......@@ -27,22 +27,39 @@ const data = [
class Component {
tag;
attribute;
children;
constructor(tag, children) {
constructor(tag, attribute, children) {
this.tag = tag;
this.attribute = attribute;
this.children = children;
}
render() {
return `<${this.tag} ${
return `<${this.tag} ${this.renderAttributes()} ${
this.children ? `>${this.children}</${this.tag}>` : ' />'
}`;
}
renderAttributes() {
if (this.attribute) {
return `${this.attribute.name}="${this.attribute.value}"`;
}
return '';
}
}
class Img extends Component {
constructor(url) {
super('img', { name: 'src', value: url });
}
}
const title = new Component('h1', 'La carte');
const title = new Component('h1', null, 'La carte');
document.querySelector('.pageTitle').innerHTML = title.render();
const img = new Component('img');
const img = new Img(
'https://images.unsplash.com/photo-1532246420286-127bcd803104?fit=crop&w=500&h=300'
);
document.querySelector('.pizzasContainer').innerHTML = img.render();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment