seajs/seajs — pull request #1279 by akfish (2014-07-28 15:57:04+00:00)
Title: Add web worker support

## Description

This PL made some necessary changes that allows developers to import sea.js from a web work and then use it to load CMD modules.
Since web workers have no access to DOM object, implementation before this PL won't be able to run in a web worker context.

## Change List

* Determine and set environment flags `isBrowser` and `isWebWorker`
* Wrap browser specific operations inside `if (isBrowser)` block
* Load scripts with `importScripts` when running in a web worker
* Add test `spec/web-worker`

## Status

* Passed all original tests
* Passed `spec/web-worker`
* Manually tested in Chrome 36, FireFox 31 and IE 11

## Use Cases

Common modules can be required from both browser and worker:
```javascript
// Common modules
// adder.js
define(function(require, exports, module) {
module.exports = function (a, b) { return a + b; }
});
```

Load sea.js once at the beginning of a worker script:
```javascript
// Worker script
// worker.js
// Import sea.js
importScripts("path/to/sea.js");

seajs.use('task');
```

Use sea.js to load other modules in worker task:
```javascript
// task.js
define(function(require, exports, module) {
// Set up message listener
// ..
// On some message
// require in worker
adder = require('./adder')
console.log(adder(1, 2));
// Send result to browser script
// ...
});
```

```html

```