Tuesday 16 May 2017

Is it possible to call a local function of the same name with a node require and module exports

For example I have a file app.js and greet.js module is it possible to call the local greet function without having to rename it?

//Contents of app.js

var greet = require('./greet.js');

//local greet function, how do I call this one?
function greet() {
    console.log('hi');
}

greet(); //Call greet in module

//Smashing the modules import of greet
var greet = function () {
   console.log("Hello pal!");
}

greet();

and the other file is greet.js

var greet = function () {
   console.log("Hello from module!");
}

module.exports = greet;



via MrDaniel

No comments:

Post a Comment