Thursday, 8 June 2017

Proper way to require libs in multiple files

I have two files - one with main code execution, and other just has a class in it.

For example:

File_1:

const _ = require('underscore'),
CoolClass = require('CoolClass');

_.map(//something)

Files_2:

const _ = require('underscore');

class CoolClass(){
  constructor(){
    _.map(//something);
  }
}

What's the proper way to require a library?

Should I require it in both files our should just require it in the main one and just pass it to constructor like:

let cool_stuff = new CoolClass(_);

Or should I pass it when I require it, so:

const _ = require('underscore')(_);

Thanks!



via Nausik

No comments:

Post a Comment