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);
    }

};
2
  • So if I understand correctly, you need to save the above in logging.js and use <script src="logging.js"></script> in each file Commented Aug 14, 2016 at 6:59
  • This question already has an answer: stackoverflow.com/a/950146/6714194 Commented Aug 14, 2016 at 7:00

2 Answers 2

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'));
});
Sign up to request clarification or add additional context in comments.

Comments

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'

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.