2

I have written a JScript file for logging purposes. and I need to import that logging js file for every other JScript file. (without copying logging functionality every file).

Basically what I need is import JScript to another JScript.

Log.js

var Log = function(filename) {
    this.fso = new ActiveXObject('Scripting.FileSystemObject');
    this.file = this.fso.OpenTextFile(filename,2,true, 0);
};

Log.prototype = {

    info: function (msg) {
        this.log('INFO ' + msg);
    },

    error: function (msg) {
        this.log('ERRO ' + msg);
    }

};
sanjay
  • 1,020
  • 1
  • 16
  • 38

2 Answers2

1

Instead of importing more than one files to HTML.

It's better to combine it into one single file and then import it, as it increases the page loading speeds and it will only send a single request to the server for the javascript file.

To combine, two or more javascript file. I suggest you go with this.

Here is the example, how to use it:

var concat = require('gulp-concat');

gulp.task('combinejs', function() {
    gulp.src([
        'one.js',
        'two.js'
        ])
        .pipe(plumber())
        .pipe(concat('all.js'))
        .pipe(gulp.dest('js'));
});
Yashu Mittal
  • 1,478
  • 3
  • 14
  • 32
0

You can export log object from logging.js

export Log;

you can import it in any js file

import {Log} from './path/of/your/logging.js'