Reputation: 1032
I'm trying to use a library that is realized by relying a lot on window.setTimeOut
. I want to use it in a worker thread that doesn't have access to the window
scope.
Is it possible to use a polyfill or use any other method that does the same thing within this context?
Upvotes: 0
Views: 1847
Reputation: 53129
You can use setTimeout
(not ) perfectly well. Just use it as global variable:setTimeOut
setTimeout( ... stuff stuff stuff ..., number);
And if you want to use global scope object for some reason, self
is defined both in Browser and Web Worker:
self.setTimeout( ... stuff stuff stuff ..., number);
If a library is trying to access window
, just define it to be global scope:
self.window = self;
window.setTimeout( ... stuff stuff stuff ..., number);
If you have further doubts, please check this jsfiddle: https://jsfiddle.net/ryovLea1/1/
Upvotes: 2