Skip to content

Instantly share code, notes, and snippets.

@clux
Last active October 11, 2015 07:18
Show Gist options
  • Save clux/3823024 to your computer and use it in GitHub Desktop.
Save clux/3823024 to your computer and use it in GitHub Desktop.
Prevent JavaScript extensions/replacement of native objects because implicit dependencies and evil.js are bad things
var classes = [Object, Array, String, RegExp, Date, Number, Function];
var nonClasses = [Math, JSON, console];
classes.concat(nonClasses).forEach(function (o) {
Object.freeze(o);
});
classes.forEach(function (o) {
Object.freeze(o.prototype);
});
// if in browser, freeze: document, XMLHttpRequest, alert, prompt as wel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment