HaxeFoundation/haxe — pull request #2122 by dpeek (2013-08-27 11:24:53+00:00)
Title: Don't check for undefined window in js.Browser (browsers have windows)

A small change to js.Browser.window and friends resulting in slightly more compact code. I'm not sure I understood the motivation of the original `window == undefined` checks. Even if we are protecting node users who think there is a window to access, an undefined reference error seems about as helpful as a null reference error (unless undefined != null for some reason).

I also added window to the `kwds` hash in `genjs.ml` incase there is a conflict. Apologies if I haven't thought through all the implications, just a small improvement to make things look more "native".

```haxe
class Test
{
static function main()
{
var element = js.Browser.document.createElement("div");
element.innerHTML = "Hello World";
js.Browser.document.appendChild(element);
}
}
```

Output before:

```JavaScript
(function () { "use strict";
var Test = function() { }
Test.main = function() {
var element = js.Browser.document.createElement("div");
element.innerHTML = "Hello World";
js.Browser.document.appendChild(element);
}
var js = {}
js.Browser = function() { }
js.Browser.document = typeof window != "undefined" ? window.document : null;
Test.main();
})();
```

Output after:

```JavaScript
(function () { "use strict";
var Test = function() { }
Test.main = function() {
var element = window.document.createElement("div");
element.innerHTML = "Hello World";
window.document.appendChild(element);
}
Test.main();
})();
```