From c723fecc4c8c7a9cc305bd3b74ffc629e0895ca8 Mon Sep 17 00:00:00 2001 From: Thomas Fritsch <tf@kumquats.fr> Date: Fri, 7 Feb 2020 17:01:25 +0100 Subject: [PATCH] B.3.2. Component de base --- js/main.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/js/main.js b/js/main.js index daca832..4616e18 100644 --- a/js/main.js +++ b/js/main.js @@ -22,13 +22,21 @@ const data = [ } ]; -class Animal { - constructor( name ){ - this.name = name; +class Component { + tag; + children; + + constructor( tag, children ){ + this.tag = tag; + this.children = children; } - fly() { // déclaration de méthode - console.log(`${this.name} is flying !`); + + render() { + return `<${this.tag}> + ${this.children ? this.children : ''} + </${this.tag}>`; } } -const threeEyedRaven = new Animal( 'Bran' ); -threeEyedRaven.fly(); \ No newline at end of file + +const title = new Component( 'h1', 'La carte' ); +document.querySelector('.pageTitle').innerHTML = title.render(); \ No newline at end of file -- GitLab