1 |
|
2 | var Ticket = require('./ticket');
|
3 |
|
4 | function Tickets() {
|
5 | this.tickets = [];
|
6 | }
|
7 |
|
8 | Tickets.prototype._apply = function (fn, args) {
|
9 | this.tickets.forEach(function (ticket) {
|
10 | ticket[fn].apply(ticket, args);
|
11 | })
|
12 | }
|
13 |
|
14 | Tickets.prototype.push = function (ticket) {
|
15 | var self = this;
|
16 | if (ticket instanceof Tickets) {
|
17 | return ticket.tickets.forEach(function (ticket) {
|
18 | self.push(ticket)
|
19 | })
|
20 | }
|
21 | if (ticket instanceof Ticket) {
|
22 | if (self.tickets.indexOf(ticket) === -1) {
|
23 | self.tickets.push(ticket);
|
24 | }
|
25 | }
|
26 | }
|
27 |
|
28 | Object.keys(Ticket.prototype).forEach(function (method) {
|
29 | Tickets.prototype[method] = function () {
|
30 | this._apply(method, arguments);
|
31 | }
|
32 | })
|
33 |
|
34 | module.exports = Tickets;
|