Question: I have two .js files. On the first .js file i declare and execute a function like this:

```
(function($){
  function something(){
    //code here
  }

  $(document).ready(function(){
    something();
  });
})(jQuery);

```

Also, I want to execute the something() function in the second .js. My code is the following:

```
(function($){
  $(document).ready(function(){
    //more code
    something();
    //more code
  });
})(jQuery);

```

However, when the program is executed, I get the following error:
Uncaught ReferenceError: something is not defined(…)

**Possible Solution:**
I solved the problem declaring the function as:

```
(function($){
  this.something = function(){
    //code here
  }

})(jQuery);

```

Is this 100% right?

Answer: 
You cant define a function inside a scope and try to use that function in another scope. You have not understood how functions and scopes work in JavaScript.

[Have a look at this](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Functions).
It's normal, you declared your function `something` in an [IIFE](https://en.wikipedia.org/wiki/Immediately-invoked_function_expression), so you can't using it outside your block. Try to declare your function outside `(function($) ...)()` block.