load Gun once in NW.js's JavaScript Contexts

In the NW.js's JavaScript Contexts, `require`, `window` are both defined...
[JavaScript Contexts in NW.js](http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/)
This commit is contained in:
SwhGo_oN 2017-06-06 20:07:03 +08:00 committed by GitHub
parent b0662c2464
commit bb4dae2d04

6
nts.js
View File

@ -2,8 +2,10 @@
var env;
if(typeof global !== "undefined"){ env = global }
if(typeof require !== "undefined"){ var Gun = require('./gun') }
if(typeof window !== "undefined"){ var Gun = (env = window).Gun }
else {
if(typeof require !== "undefined"){ var Gun = require('./gun') }
}
Gun.on('opt', function(at){
this.to.next(at);
@ -43,4 +45,4 @@
}; ping();
});
// test by opening up examples/game/nts.html on devices that aren't NTP synced.
}());
}());