Question: I want to run a function after several events has happened with event listener like:

```
listenTo(eventA occurred && eventB occured && eventC occurred) {
    do something.
}

```

How can I accomplish that?

Answer: 
Please try it with [`Promise.all`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)

```
var p1 = new Promise(function(resolve, reject) { 
  listenTo(eventA, resolve);
}); 
var p2 = new Promise(function(resolve, reject) { 
  listenTo(eventB, resolve);
});
var p3 = new Promise(function(resolve, reject) {
  listenTo(eventC, resolve);
});

Promise.all([p1, p2, p3]).then(function(value) { 
  // all three events are triggered.
  doSomething...
});

```
You should add event listener to each event, if event happen you should store it in some flag variable that is accessible in each event handler, after that check if all flags are true if so `doSomething`. Instead of flag variables you can use map, also you can create some helper function which will recieve all events and retrive callback when all events happen, it all to style of your implementation. 
I don'the think that you can find much better approach for that task