I am developing a Nodejs module, which is a function and returns an object with a function in a property. If I call the module without any parameter returns error (Test is not a constructor). If I call the module passing a parameter, even if it is empty, it works properly.
Example #1
(App)
//var test = require('./index.js')().Test; // Works properly
var test = require('./index.js').Test;
var sample = new test('text', function(newText) {
console.log(newText);
});
(Module)
module.exports = function(options) {
var bold = 0;
var anotheModule = new anotherModule(options); //If the parameters are not defined, take the default.
console.log('Check 1');
return {
Test: Test
}
function Test(text) {
.....
}
}
Example #2
(Module)
module.exports = function textChange(options) {
var bold = 0;
var anotheModule = new anotherModule(options); //If the parameters are not defined, take the default.
console.log('Check 1');
}
textChange.prototype.Test = function(text) {
.....
}
Example #3
(Module)
function textChange(options) {
var bold = 0;
var anotheModule = new anotherModule(options); //If the parameters are not defined, take the default.
console.log('Check 1');
}
textChange.prototype.Test = function(text) {
.....
}
module.exports = textChange;
Example #4
(Module)
function textChange(options) {
var bold = 0;
var anotheModule = new anotherModule(options); //If the parameters are not defined, take the default.
console.log('Check 1');
}
Test = function(text) {
.....
}
module.exports = textChange;
export.Test = Test;
I can't get the solution to work without passing parameters. I can't get the solution to work without passing parameters. If the application calls the module with parameters, it works correctly.