How does one implement 'protected variables' in javascript?

```
var DIM = {
  makeOneDim: function(x) {
    var magic = Math.random();
    return {
      dist: function() {
        return x * magic;
      }
    };
  },
  makeTwoDim: function(x,y) {
    var o = DIM.makeOneDim(x);
    o.dist = function() {       
      magic *= Math.random();
      return Math.sqrt(x*x+y*y) * magic;
      // !! cant access 'private' variable magic !!
    }
    return o;
  }
};
var o = DIM.makeOneDim(123);
var oo = DIM.makeTwoDim(1,2);
console.log(o.dist() + oo.dist());

```

I know in this example it would be possible to make a 'public getter', but i would still want to mutate the magic variable from within makeTwoDim's scope and hide it from its instances.

It would also be nice if I could somehow prevent recreating the dist functions on each creation of an instance.