Lets split a requireJs module in its part to understand what happens:
Let requireJs know that this is a module
define(
Some dependencies
[ 'common'],
So this is the main part. After all this just a function that is called when loaded. RequireJs save the result of the function and inject it in every module that has this module as dependencies
function(Common) {
return
So this is what every module get when it require this module
{
func1: function() {
return 'this is function 1';
},
func2 : function (data){
console.log(func1);
}
};
So in your case you return just a simple object with to 2 functions as it members.
What you try to do cant work cause there is no func in the scope, aka the function that returns the object.
But a there is member func in your object, so you can call this.func1.
You can also have a function in your function like this:
define([
'common'
], function(Common) {
function func1() {
return 'this is function 1';
}
return {
func2 : function (data){
console.log(func1);
}
};
});
But then func1 isn't accessible from outside