Friday, 6 December 2019

javascript - Export and reuse overloaded functions of a js file in another js file

I am trying export all the overloaded functions of a js file. So that I can reuse them in other js files. But, whenever I am trying to call any function.then the highest parameterized function is getting called every time.



reusefun.js




exports.getMessage = function(val1) {
return val1;
}
exports.getMessage = function(val1,val2) {
return val1+ " " +val2;
}
exports.getMessage = function(val1,val2,val3) {
return val1+ " " +val2+ " " +val3;
}



Suppose I am using this file like below



myfile.js



const re = require('./reusefun);
console.log(re.getMessage("a"));



Then getMessage(val1,val2,val3) is getting called instead of getMessage(val1) .

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...