Question: This is probably a basic question, and I am aware that there have been some similar questions around here, but still I did not find an answer. Please consider the following code:

```
function Outer(inner2) {
  var x = 5;
  this.inner1 = function() {return (x);}
  this.inner2 = inner2.bind(this);
}
var outer = new Outer(function() {return (x);});
alert(outer.inner1()); // works
alert(outer.inner2()); // does not work

```

If I would replace the second line by `this.x = 5;`, the second alert would work. So I guess the problem is that `x` when declared with `var` is not part of `this`, so that `bind` will have no effect.

Is there any way to make this work without using `this.x`?

Answer: 
> 
> Is there any way to make this work without using `this.x`?
> 
> 
> 

[No](https://stackoverflow.com/q/13418669/1048572?javascript-do-i-need-to-put-this-var-for-every-variable-in-an-object).

Btw, you probably don't even need to use `bind`, just calling `inner2` as a method on the object would suffice when both the constructor and the method use `this.x`. 

If you don't want to make `x` a property of the object, but keep it as a local variable, the usual strategy would be to pass it to the callback as an argument, not trying to somehow make it available in its scope implicitly:

```
function Outer(callback) {
  var x = 5;
  this.inner1 = function() { return x; };
  this.inner2 = function() { return callback(x); };
//                                          ^^^
}
var outer = new Outer(function(y) { return y; });
//                             ^           ^
alert(outer.inner1()); // works
alert(outer.inner2()); // works

```
I found an, albeit ugly, solution:

```
function Outer(inner2) {
  var x = 5;
  this.inner1 = function() {return (x);}
  eval('this.inner2 = ' + inner2.toString());
}

```

This works and shows my point: the parameter `inner2` is just a prescription of how `this.inner2` should look like; it is never invoked itself.

Let me know, if you have a neater solution than this.