Skip to content

Instantly share code, notes, and snippets.

@annibal
Last active May 21, 2024 03:48
Show Gist options
  • Save annibal/4c881e25beb72ec82e60e7a7dd01c68a to your computer and use it in GitHub Desktop.
Save annibal/4c881e25beb72ec82e60e7a7dd01c68a to your computer and use it in GitHub Desktop.
Immediately Invoking, Anonymous, Recursive Function Expression
(function() {
const c = confirm("again?")
if (!c) return;
if (c === true) {
eval(`(${arguments.callee.toString()})()`)
}
})()
(function() {
return Function(
"return (" +
(function() {
const c = confirm("again?")
if (!c) return;
if (c === true) {
eval(`(${arguments.callee.toString()})()`)
}
}).toString() +
")()")
})()
// Usage:
setTimeout(
(function() {
return Function(
"return (" +
(function() {
// makes it rather hard to find and stop a self-calling function that has no name
const c = confirm("Can i have your cookies now?");
if (c === true) {
try {
collectCookiesFromThisUser();
} catch (e) {}
alert("Thanks for the cookies!");
return;
}
setTimeout(`(${arguments.callee.toString()})()`, 3000)
}).toString() +
")()")
})(),
3000
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment