Last active
May 28, 2019 14:32
-
-
Save AJLoveChina/30475a28513f36c57166e19cb1bf047b to your computer and use it in GitHub Desktop.
EventEmitter class extend demo https://jsbin.com/losabat/edit?js,output
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script src='https://cdnjs.cloudflare.com/ajax/libs/EventEmitter/5.2.6/EventEmitter.min.js'></script> | |
<script id="jsbin-javascript"> | |
class Dog extends EventEmitter { | |
constructor() { | |
super() | |
this.barks = 0; | |
setInterval(() => { | |
this.trigger("bark", [this.barks ++]); | |
}, 1000) | |
} | |
} | |
let d = new Dog(); | |
d.on("bark", barks => { | |
document.writeln(barks) | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment