Let global inherit from self in Node.JS.

This commit is contained in:
Eddie Antonio Santos 2018-10-11 10:10:35 -06:00
parent a1b3be77e3
commit 7839a50e16
No known key found for this signature in database
GPG key ID: DD411EA4D9509D87
3 changed files with 13 additions and 4 deletions

View file

@ -287,7 +287,7 @@ TODO
- [ ] Change `context` to `contexts`.
- [ ] Figure out what a `Context` will be
- [ ] Implement hack to make `global` inherit from `self`
- [x] Implement hack to make `global` inherit from `self`
- [ ] Define on `self.registerModel(m: Model)` protocol
- [ ] Describe `contexts`
- [ ] make simple `index.html` that demos a dummy model

View file

@ -65,4 +65,14 @@ function loadModelClass() {
return global.Model;
}
/**
* HACK: on Node.JS + tiny-worker, ensure code imported with importScripts()
* has access to the same things defined on self in this file.
*/
if (typeof global !== 'undefined') {
let globalPrototype = Object.getPrototypeOf(global);
Object.setPrototypeOf(self, globalPrototype);
Object.setPrototypeOf(global, self);
}
/*global importScripts*/

View file

@ -18,7 +18,6 @@ class Model {
}
// TODO: shouldn't this be running in the same scope as the original?
// TODO: test in a browser!
if (typeof global !== 'undefined') {
global.Model = Model;
}
global.Model = Model;
}