5 kyu
Simple Events
4,560 of 6,033akoptsov
Description:
Your goal is to write an Event constructor function, which can be used to make event objects.
An event object should work like this:
- it has a .subscribe() method, which takes a function and stores it as its handler
- it has an .unsubscribe() method, which takes a function and removes it from its handlers
- it has an .emit() method, which takes an arbitrary number of arguments and calls all the stored functions with these arguments
As this is an elementary example of events, there are some simplifications:
- all functions are called with correct arguments (e.g. only functions will be passed to unsubscribe)
- you should not worry about the order of handlers' execution
- the handlers will not attempt to modify an event object (e.g. add or remove handlers)
- the context of handlers' execution is not important
- each handler will be subscribed at most once at any given moment of time. It can still be unsubscribed and then subscribed again
Also see an example test fixture for suggested usage
Design Patterns
Event Handling
Fundamentals
Similar Kata:
Stats:
Created | Jan 13, 2014 |
Published | Jan 13, 2014 |
Warriors Trained | 14328 |
Total Skips | 3656 |
Total Code Submissions | 28832 |
Total Times Completed | 6033 |
JavaScript Completions | 4560 |
Ruby Completions | 203 |
Python Completions | 1314 |
Total Stars | 354 |
% of votes with a positive feedback rating | 85% of 586 |
Total "Very Satisfied" Votes | 439 |
Total "Somewhat Satisfied" Votes | 116 |
Total "Not Satisfied" Votes | 24 |