First of all, I know that with the help of this
it is possible to access properties or methods within a javascript object, but something doesn't work in my example.
module.exports = {
explanations: {
'--help': 'show help',
'--connection': 'list connections'
},
connections: {
'a': '1',
'b': '2',
'c': '3'
},
manPageOfObject: function(object) {
var output = '';
var keys = Object.keys(object);
for (var i in keys) {
output += keys[i] + ': ' + object[keys[i]] + '\n';
}
return output;
},
manPages: {
'--help': function() { return this.manPageOfObject(this.explanations); }
'--connections': function() { return this.manPageOfObject(this.connections); }
}
}
The function manPageOfObject
should return a string/"man page" of an object.
Then I want to print a "man page" like:
var myModule = require('xyz.js');
var manPage = myModule.manPages['--help'];
console.log(manPage());
But something isn't working properly, I get the error this.manPageOfObject
is not a function. But I'm pretty sure it is one, isn't it?
I appreciate any help. Thanks.