Skip to content

Commit

Permalink
Classes, Inheritance, and a Closer Component Look
Browse files Browse the repository at this point in the history
  • Loading branch information
15Dkatz committed Oct 19, 2022
1 parent 0cc0f8c commit 2c3038d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
9 changes: 9 additions & 0 deletions portfolio/src/App.js
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
39 changes: 39 additions & 0 deletions portfolio/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,42 @@ import App from './App';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);

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);

0 comments on commit 2c3038d

Please sign in to comment.