browserify/timers-browserify

Running inside web-worker window is undefined

Closed this issue · 2 comments

When running in the context of web-worker the window variable is undefined, is it possible to remove reference to it ?

Following the places where window is used.

exports.setTimeout = function() {
  return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
};
exports.setInterval = function() {
  return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
};
Timeout.prototype.close = function() {
  this._clearFn.call(window, this._id);
};

Seems like we could do something like:

var scope = this;

at the top of the module and replace those windows with scope. Feel free to submit a PR if that works for you!

Just did