A case for removing the seal/freeze/isSealed/isFrozen traps
Nathan Wall
nathan.wall at live.com
Mon Feb 18 13:09:37 PST 2013
David Bruant wrote:
> ...
> "Security" is very loaded with emotions of people afraid to have their
> password stolen and "cyber attacks". It's also loaded with the notion of
> human safety and human integrity which, as human beings are sensitive to.
> Maybe I should start using a different word...
Great explanation, David. That's everything I've wanted to say but haven't been able to find the words. Thanks for this!
Also, I've started using the word "integrity" to describe this kind of code, to get away from the loadedness of "security". For instance, Mark Miller's "low-integrity" puzzle[1]:
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]; }
});
}
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]; }
});
}
Of course, you don't want to write this way all the time. I think it's good for library code.
[1] http://mail.mozilla.org/pipermail/es-discuss/2011-November/017964.html
Nathan
More information about the es-discuss
mailing list