On Thu, Nov 3, 2011 at 7:55 PM, Mark S. Miller <[email protected]> wrote:
>
> function makeTable() {
> var array = [];
> return Object.freeze({
> add: function(v) { array.push(v); },
> store: function(i, v) { array[i] = v; },
> get: function(i) { return array[i]; }
> });
> }
>
> Given just a table instance, can Bob nevertheless obtain direct access to
> the underlying array?
>
So Bob can cheat by extending Array.prototype, right?
Object.defineProperty(Array.prototype, 'self', {
get: function() {
return this;
}
});
console.log(table.get('self'));
That's why Douglas proposes using var array = Object.create(null), an
object without a prototype that can be extended.
Juan
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss