Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topic 2 #107

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions 02-oop-inheritance/Exercise1/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>
<html class="no-js" lang="es">

<head>
<meta charset="utf-8">
<title>Bootcamp - Topic 2 - E1</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/style.css">
<meta name="theme-color" content="#fafafa">
</head>

<body>
<div>
<footer>
</footer>
</div>
<script type="text/javascript" src="js/script.js"></script>
</body>

</html>
38 changes: 38 additions & 0 deletions 02-oop-inheritance/Exercise1/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class Actor {
constructor(name, age) {
this.name = name;
this.age = age;
}
}

class Movie {
constructor(name, year, duration) {
this.name = name;
this.year = year;
this.duration = duration;
}
play() {

}
pause() {

}
resume() {

}
}

class EventEmitter {
func(event, logger) {
logger(event, "Triggered");
}
on(event, logger) {
document.addEventListener(event.type, this.func(event, logger));
}
emit(event) {
document.dispatchEvent(event);
}
off(event, logger) {
document.removeEventListener(event.type, this.func(event, logger))
}
}
21 changes: 21 additions & 0 deletions 02-oop-inheritance/Exercise2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>
<html class="no-js" lang="es">

<head>
<meta charset="utf-8">
<title>Bootcamp - Topic 2 - E1</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/style.css">
<meta name="theme-color" content="#fafafa">
</head>

<body>
<div>
<footer>
</footer>
</div>
<script type="text/javascript" src="js/script.js"></script>
</body>

</html>
44 changes: 44 additions & 0 deletions 02-oop-inheritance/Exercise2/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class EventEmitter {
func(event, logger) {
logger(event, "Triggered");
}
on(event, logger) {
document.addEventListener(event.type, this.func(event, logger));
}
emit(event) {
document.dispatchEvent(event);
}
off(event, logger) {
document.removeEventListener(event.type, this.func(event, logger))
}
}

class Actor {
constructor(name, age) {
this.name = name;
this.age = age;
}
}

class Movie {
constructor(name, year, duration) {
this.name = name;
this.year = year;
this.duration = duration;
}
play(logger) {
let play = new CustomEvent("play");
this.on(play, logger);
this.emit(play);
}
pause(logger) {
let pause = new CustomEvent("pause");
this.on(pause);
this.emit(pause);
}
resume(logger) {
let resume = new CustomEvent("resume");
this.on(resume);
this.emit(resume);
}
}
21 changes: 21 additions & 0 deletions 02-oop-inheritance/Exercise3/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>
<html class="no-js" lang="es">

<head>
<meta charset="utf-8">
<title>Bootcamp - Topic 2 - E1</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/style.css">
<meta name="theme-color" content="#fafafa">
</head>

<body>
<div>
<footer>
</footer>
</div>
<script type="text/javascript" src="js/script.js"></script>
</body>

</html>
66 changes: 66 additions & 0 deletions 02-oop-inheritance/Exercise3/js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class EventEmitter {
on(event, callback) {
document.addEventListener(event, callback);
}
emit(event) {
document.dispatchEvent(event);
}
off(event) {
document.removeEventListener(event, callback);
}
}

class Actor {
constructor(name, age) {
this.name = name;
this.age = age;
}
}

class Movie extends EventEmitter {
constructor(title, year, duration) {
super();
this.title = title;
this.year = year;
this.duration = duration;
this.cast = [];
this.playEvent = new CustomEvent("play");
this.pauseEvent = new CustomEvent("pause");
this.resumeEvent = new CustomEvent("resume");
}
play() {
this.emit(this.playEvent);
}
pause() {
this.emit(this.pauseEvent);
}
resume() {
this.emit(resumeEvent);
}
addCast(cast) {
if (Array.isArray(cast)) {
this.cast = this.cast.concat(cast);
return;
}
this.cast.push(cast);
}
}

class Logger {
log(event) {
console.log(`The ${event}'s event has been emited`);
}
}
const logger = new Logger();
const terminator = new Movie('Terminator I', 1985, 60);
const arnold = new Actor('Arnold Schwarzenegger', 50);
const actors = [
new Actor('Paul Winfield', 50),
new Actor('Michael Biehn', 50),
new Actor('Linda Hamilton', 50)
];

terminator.addCast(arnold);
terminator.addCast(actors);

terminator.on('play', logger.log("play"));
21 changes: 21 additions & 0 deletions 02-oop-inheritance/Exercise4/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>
<html class="no-js" lang="es">

<head>
<meta charset="utf-8">
<title>Bootcamp - Topic 2 - E1</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/style.css">
<meta name="theme-color" content="#fafafa">
</head>

<body>
<div>
<footer>
</footer>
</div>
<script type="text/javascript" src="js/script.js"></script>
</body>

</html>
78 changes: 78 additions & 0 deletions 02-oop-inheritance/Exercise4/js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
class EventEmitter {
on(event, callback) {
document.addEventListener(event, callback);
}
emit(event) {
document.dispatchEvent(event);
}
off(event) {
document.removeEventListener(event, callback);
}
}

class Actor {
constructor(name, age) {
this.name = name;
this.age = age;
}
}

class Movie extends EventEmitter {
constructor(title, year, duration) {
super();
this.title = title;
this.year = year;
this.duration = duration;
this.cast = [];
this.playEvent = new CustomEvent("play");
this.pauseEvent = new CustomEvent("pause");
this.resumeEvent = new CustomEvent("resume");
}
play() {
this.emit(this.playEvent);
}
pause() {
this.emit(this.pauseEvent);
}
resume() {
this.emit(resumeEvent);
}
addCast(cast) {
if (Array.isArray(cast)) {
this.cast = this.cast.concat(cast);
return;
}
this.cast.push(cast);
}
}

class Logger {
log(event) {
console.log(`The ${event}'s event has been emited`);
}
}

let Social = {
share(friendName) {
console.log(friendName + " shares " + this.title);
},
like(friendName) {
console.log(friendName + " likes " + this.title);
}
};

Object.assign(Movie.prototype, Social);

const logger = new Logger();
const terminator = new Movie('Terminator I', 1985, 60);
const arnold = new Actor('Arnold Schwarzenegger', 50);
const actors = [
new Actor('Paul Winfield', 50),
new Actor('Michael Biehn', 50),
new Actor('Linda Hamilton', 50)
];

terminator.addCast(arnold);
terminator.addCast(actors);
terminator.share("Chuck Norris");
terminator.like("Chuck Norris");
Empty file added topic-0/css/main.css
Empty file.
Loading