as a "high-integrity" function:

    var freeze = Object.freeze,
        push = Function.prototype.call.bind(Array.prototype.push);
    function makeTable() {
      var array = [];
      return freeze({
        add: function(v) { push(array, v); },
        store: function(i, v) { array[i >>> 0] = v; },
        get: function(i) { return array[i >>> 0]; }
      });
    }

Careful there, you're not done!-) With nodejs, adding the following

   var table = makeTable();
   table.add(1);
   table.add(2);
   table.add(3);

   var secret;
   Object.defineProperty(Array.prototype,42,{get:function(){ secret = this;}});

   table.get(42);
   console.log(secret);
   secret[5] = "me, too!";

   console.log( table.get(5) );

to your code prints

   $ node integrity.js
   [ 1, 2, 3 ]
   me, too!

Couldn't resist,
Claus

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to