It's a chain. three functions are calling here:
- call init from b.js:
a.init( 5 )
- call init from a.js:
init = function( aa ) { ... }
- call some from a.js:
some = function( aa ) { ... }
every function return undefined by default, so if u want to pass your calculated value through all of this, you need to return it in every function.
new a.js
var a = (function(){
var some = function(aa) {
return aa + 10;
}
var init = function(aa) {
return some(aa);
}
return {
init : init
}
})();
now call your b.js file, and it will work as expected.
Update:
if you would like to get rid of those return values, you can use arrow-functions like this:
var a = (function(){
var some = aa => aa + 10;
var init = aa => some(aa);
return {
init : init
}
})();
they will return calculated value by default ( instead of undefined ).
somefunction. change it toreturn aa + 10. also yourinitfunction, toreturn some( aa )