Question: I'm working in Java and I want to put in situation about the thing that I need to do.

I have an integer (for example: 4) and I need to do an array of that number of dimmensions.

If it's 1... it's easy because I can write

```
int[] v1 = new int[X];

```

in this case X doesn't matter...

but the problem is when I have a 12 for example... that it's a bad solution to use:

```
int[][][][][][][][][][][][] v2 = new int[X][X][X][X][X][X][X][X][X][X][X];

```

So my question is:
How can I make a loop for this problem and avoid to write all the cases until for example 30? because I think that that's a bad way to do it. 

Thanks.

Answer: 
I just tested this. And it works like charm.

```
'use strict'

function foo () {
  return 'foo';
}

exports.foo = foo;

function bar () {
  return exports.foo(); // <--- notice
}

exports.bar = bar;

```

> 
> Explanation
> 
> 
> 

when you do `sinon.stub(myModule, 'foo').returns('foo2')` then `sinon` stubs the `exported` object's `foo` not the actually `foo` function from inside your `myModule.js` ... as you must know, `foo` is in accessible from outside the module. So when you set `exports.foo`, the exported object `exports.foo` stores the ref of `foo`. and when you call `sinon.stub(myModule, 'foo').returns('foo2')`, `sinon` will stub `exports.foo` and not the actual `foo`

Hope this makes sense!
I was a bit wary of using `exports` since it's a bit magical (for instance when you're coding in Typescript, you never use it directly), so I'd like to propose an alternate solution, which still requires modifying the source code unfortunately, and which is simply to wrap the function to be stubbed into an object:

```
export const fooWrapper = {
    foo() {...}
}

function bar () {
    return fooWrapper.foo()
}

```

And `sinon.stub(fooWrapper, 'foo')`. It's a bit a shame having to wrap like that only for testing, but at least it's explicit and type safe in Typescript (contrary to to `exports` which is typed `any`).