javascript - Require and extend classes in Electron, how to? -


i have file global.js contains

var global = (function () {     function global() {         this.greeting = 'test';     }      global.prototype.getlist = function () {         return "hello, " + this.greeting;     };     return global; })(); 

and file 'main.js', contains

var global= new global();  console.log(global.getlist); 

then require them in index.html

... <script>     require('./npmmain.js');     require('./main.js'); </script> 

and global not defined

how can make class available main.js?

any ideas?

edit: if console.log('test'); inside npmmain.js can see run, file getting required, class not available or

welcome world of modules!

first, inside of main.js file, add line @ top this:

var global = require('./npmmain.js').global; 

then @ end of npmmain.js add line this:

exports.global = global; 

then remove line index.html. should it.

i guessing not familiar commonjs style modules. modules not share global variables. (except few properties supplied commonjs implementation) needs required before can used. also, if want expose values between modules, need use exports keyword.

there more detailed explanation on commonjs site.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -