forked from globant-ui/startup
-
Notifications
You must be signed in to change notification settings - Fork 1
Making classes and instances.. #5
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
Open
tinchoaranda05
wants to merge
2
commits into
master
Choose a base branch
from
topic-02
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| class movie { // Making class movie | ||
|
|
||
| constructor(title, year, duration){ | ||
| this.title = title; | ||
| this.year = year; | ||
| this.duration = duration; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| play(title){ | ||
| var playVideo = document.getElementById(title); | ||
| playVideo.reset(); | ||
| playVideo.play(); | ||
| } | ||
| pause(title){ | ||
| var pauseVideo = document.getElementById(title); | ||
| pauseVideo.pause(); | ||
| } | ||
| resume(title){ | ||
| var resumeVideo = document.getElementById(title); | ||
| resumeVideo.play(); | ||
| } | ||
| } | ||
|
|
||
| function playVideo(data) { | ||
| var myVideo = document.getElementById(data); | ||
| myVideo.play(data); | ||
| } | ||
|
|
||
| function pauseVideo(data) { | ||
| var myVideo = document.getElementById(data); | ||
| myVideo.pause(data); | ||
| } | ||
|
|
||
| function resumeVideo(data) { | ||
| var myVideo = document.getElementById(data); | ||
| console.log(myVideo); | ||
| myVideo.resume(data); | ||
| } | ||
|
|
||
|
|
||
| // instance of objects movie. | ||
| // Not sure what do you mean when you say "play with them in the console." | ||
|
|
||
| let StarWars = new movie("Star Wars - A new hope", "1977", "2h 5m"); | ||
| let Interstellar = new movie("Interstellar", "2014", "2h 49m"); | ||
| let TheGodfather = new movie("The Godfather", "1972", "2h 58m"); | ||
| console.log(StarWars); | ||
| console.log(Interstellar); | ||
| console.log(TheGodfather); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| class EventEmitter { | ||
|
|
||
| constructor() { | ||
| this.listeners = { | ||
|
|
||
| } | ||
| } | ||
| on(event, listener) { | ||
| if ('event' in this.listeners) { | ||
| this.listeners[event].push(listener); | ||
| } | ||
| this.listeners[event] = []; | ||
|
|
||
| } | ||
| emit(event) { // don't sure what to do here | ||
|
|
||
| console.log(this.listeners[event]); | ||
| /*this.listeners[event].forEach(function(fn){ | ||
| console.log("executing a listener"); | ||
| fn.call(window.event); | ||
| })*/ | ||
| } | ||
| off(event, listener) { | ||
| if ('event' in this.listeners){ | ||
| var del = this.listeners[event].pop(); | ||
| console.log("Deleted", del); | ||
| } | ||
| else { | ||
| console.log("empty"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| class movie extends EventEmitter { | ||
| constructor(title, year, duration) { | ||
| super(); | ||
| this.title = title; | ||
| this.year = year; | ||
| this.duration = duration; | ||
| } | ||
|
|
||
| play() { | ||
| console.log("playing ", this.title); | ||
| super.emit('play'); | ||
| } | ||
| pause() { | ||
| super.emit('pause'); | ||
| } | ||
|
|
||
| resume() { | ||
| super.emit('resume'); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // functions for play pause and resume | ||
|
|
||
| function playVideo(data){ | ||
| var video = document.getElementById(data); | ||
| video.play(); | ||
| if(data.value=="Resume") | ||
| { | ||
| data.value="Play"; | ||
| } | ||
| } | ||
|
|
||
| function pauseVideo(data) { | ||
| var myVideo = document.getElementById(data); | ||
| myVideo.pause(data); | ||
| } | ||
|
|
||
| function resumeVideo(data) { | ||
| var myVideo = document.getElementById(data); | ||
| console.log(myVideo); | ||
| myVideo.resume(data); | ||
| } | ||
|
|
||
| var myEventEmitter = new EventEmitter(); | ||
| myEventEmitter.on('Play Event', playVideo); | ||
|
|
||
| var firstEventButton = document.getElementById("firstEvent"); | ||
| firstEventButton.addEventListener('click', function(){ | ||
| myEventEmitter.emit('Play Event'); | ||
| },false); | ||
| console.log(myEventEmitter); | ||
|
|
||
|
|
||
|
|
||
| // instances | ||
|
|
||
| var StarWars = new movie("Star Wars - A new hope", "1977", "2h 5m"); | ||
| var Interstellar = new movie("Interstellar", "2014", "2h 49m"); | ||
| var TheGodfather = new movie("The Godfather", "1972", "2h 58m"); | ||
| console.log(StarWars); | ||
| console.log(Interstellar); | ||
| console.log(TheGodfather); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <!doctype html> | ||
|
|
||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
|
|
||
| <title>Topic 02</title> | ||
| <meta name="description" content="Exercises"> | ||
| <meta name="author" content="Martin Aranda"> | ||
| </head> | ||
|
|
||
| <body> | ||
|
|
||
|
|
||
| <section> | ||
| <div> | ||
| <video id="Star Wars" src="video_1.mp4"> | ||
| </video> | ||
| <input id ="firstEvent" type="button" onclick="playVideo('Star Wars')" value="Play" ></input> | ||
| <input type="button" onclick="pauseVideo('Star Wars')" value="Pause"></input> | ||
| <input type="button" onclick="resumeVideo('Star Wars')" value="Resume"></input> | ||
| </div> | ||
| </section> | ||
|
|
||
| <script src="fun2.js"></script> | ||
| </body> | ||
| </html> |
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Si hay varios listener registrados para el mismo evento, esto no sabe cuál elimina, solo saca de a uno