Skip to content

Instantly share code, notes, and snippets.

@kidGodzilla
Created January 5, 2015 05:11
Show Gist options
  • Save kidGodzilla/0fd3ad457707481f8072 to your computer and use it in GitHub Desktop.
Save kidGodzilla/0fd3ad457707481f8072 to your computer and use it in GitHub Desktop.
Prototype an object with secret methods which self-destruct
function SecretMethods () {} (function () {
var add = function (a,b) {
return a + b;
}
var mul = function (a,b) {
return a * b;
}
var once = function (f) {
return function () {
var fn = f;
f = null;
return fn.apply(this, arguments);
};
}
var z = once(add);
SecretMethods.prototype = {
secret: z
};
}());
var g = new SecretMethods();
console.log(g.secret(3,4)); // Works, as expected
console.log(g.secret(3,4)); // Throws an error because IT HAS SELF DESTRUCTED!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment