From 2c3038d9a508e4571db8da501075e778debe73af Mon Sep 17 00:00:00 2001 From: David Katz <15Dkatz@shcp.edu> Date: Tue, 18 Oct 2022 17:20:32 -0700 Subject: [PATCH] Classes, Inheritance, and a Closer Component Look --- portfolio/src/App.js | 9 +++++++++ portfolio/src/index.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/portfolio/src/App.js b/portfolio/src/App.js index 322bb28..d168d96 100644 --- a/portfolio/src/App.js +++ b/portfolio/src/App.js @@ -1,5 +1,14 @@ import React, { Component } from 'react'; +class RegularClass {} +class ComponentClass extends Component {} + +const regularClassInstance = new RegularClass(); +const componentClassInstance = new ComponentClass(); + +console.log('regularClassInstance', regularClassInstance); +console.log('componentClassInstance', componentClassInstance); + class App extends Component { render() { return ( diff --git a/portfolio/src/index.js b/portfolio/src/index.js index 217069b..5c1146b 100644 --- a/portfolio/src/index.js +++ b/portfolio/src/index.js @@ -4,3 +4,42 @@ import App from './App'; const root = ReactDOM.createRoot(document.getElementById('root')); root.render(); + +class Animal { + constructor(name, age) { + this.name = name; + this.age = age; + } + + speak() { + console.log('I am', this.name, 'and I am', this.age, 'years old'); + } +} + +const animal1 = new Animal('Simba', 3); +animal1.speak(); + +console.log(animal1); + +class Lion extends Animal { + constructor(name, age, furColor, speed) { + super(name, age); + this.furColor = furColor; + this.speed = speed; + } + + roar() { + console.log( + 'ROOOAR! I have', + this.furColor, + 'fur, and I can run', + this.speed, + 'miles an hour!' + ); + } +} + +const lion1 = new Lion('Mufasa', 20, 'golden', 25); +lion1.speak(); +lion1.roar(); +console.log(lion1);