Reputation: 15
I tried using module.exports as well but it's not detecting module.exports in my WebStorm. So, how to enable module.exports in WebStorm? Another thing is I am trying to get function from another js file. Something like we do inheritance in Java I am expecting here in JavaScript. below is my code:- locate.js
/** * */
var locate = function()
{
var a = 10;
function inner(_block)`
{
console.log( "Hello", _block+" "+a )`;
}
locate.inner = inner;
}
locate();
locate.inner( "World" );
//console.log(locate);
module.export = locate;
delocate.js
let a;
a = require('./locate.js');
console.log(a);
a.inner("Universe");` //inner is not visible gives error
a.inner("Universe"); ^
TypeError: a.inner is not a function
Expected output should be HelloUniverse10
Upvotes: 0
Views: 125
Reputation: 93728
it can be
var locate = function() {
var a = 10;
var locate = {}
function inner(_block) {
console.log('Hello',
_block + ' ' + a);
}
locate.inner = inner;
return locate;
}
module.exports = locate;
and
const a = require('./locate')();
console.log(a);
a.inner("Universe");
Note that this has absolutely nothing to do with Webstorm; your code is run with Node.js, so it's all about javascript and commonJS modules syntax
Upvotes: 1