LearnBoost/engine.io-client — pull request #82 by ramitos (2012-12-12 17:21:38+00:00)
Title: use window to detect platform and fix global reference

#### use window to detect platform

Mocha pollutes the global object (window) with `process` object. So when testing in the client-side, engine.io will think that is in the server-side because:

```js
'undefined' != typeof process
```

Checking if
```js
'undefined' == typeof window
```
seems like a more accurate way to detect if the code is running on the server-side

#### fix global reference

Doing
```js
var global = 'undefined' != typeof window ? window : global;
```
will always define global as `undefined` (in Node) because the interpreter will lookup at every var declaration in the scope and define them as `undefined`. Then will interpret the condition and define global as `undefined` because `window` is `undefined` and `global` is also `undefined`.

Having

```js
exports.global = function () {
return 'undefined' != typeof window ? window : global;
};
```
will behave as expected because the condition has it's own scope and doesn't override `global`.

To do this, anytime the `global` variable is needed in `utils.js`we need to declare it in the function scope (`var global = exports.global();`) to not pollute the `exports.global` parent scope.

With this solution we can just call `util.global`:
```js
var global = util.global();
```
--
Sorry if the explanation wasn't clear enough :/