UNPKG

704 BJavaScriptView Raw
1
2var Ticket = require('./ticket');
3
4function Tickets() {
5 this.tickets = [];
6}
7
8Tickets.prototype._apply = function (fn, args) {
9 this.tickets.forEach(function (ticket) {
10 ticket[fn].apply(ticket, args);
11 })
12}
13
14Tickets.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
28Object.keys(Ticket.prototype).forEach(function (method) {
29 Tickets.prototype[method] = function () {
30 this._apply(method, arguments);
31 }
32})
33
34module.exports = Tickets;