LoginSignup
0
0

More than 5 years have passed since last update.

`using` in JavaScript

Posted at

Dirty. Names are assigned directly into GLOBAL. It breaks file scope.

main.js
using = require('using').using
using(require('foo'))
console.log(new Foo) #=> { name: 'Foo' }
require('bar')
using.js
exports.using = function (mod) {
    for (var name in mod)
        GLOBAL[name] = mod[name]
}
foo.js
exports.Foo = function () {
    this.name = 'Foo'
}
bar.js
console.log(new Foo) #=> { name: 'Foo' }

There may be another way but I can't find it...

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0