Skip to content

Instantly share code, notes, and snippets.

@fcalderan
Created November 2, 2010 09:42
Show Gist options
  • Save fcalderan/659424 to your computer and use it in GitHub Desktop.
Save fcalderan/659424 to your computer and use it in GitHub Desktop.
inception explained as a 4 nested javascript closures
/*
* Fabrizio Calderan, twitter @fcalderan, 2010.11.02
* I had an idea: could Inception movie be explained by a few javascript closures
* and variable resolution scope (just for fun)?
*
* Activate javascript console =)
*/
<script>
console.group("inception movie");
var inception = (function() {
/* on flight: arianna's dream */
var timerate = 1;
var team = ["Yusuf", "Arthur", "Eames", "Saito", "Arianna", "Dominic", "Mr.Fischer"];
console.log("Real world", team);
console.log("Time Rate is ", timerate);
console.log("1 second is %d second (what else?)", 1/timerate);
(function(timerate) {
/* Yusuf escape */
console.group("1th level: arianna's dream");
var kick = "fall in the water";
console.log("1th level team", team);
console.log("Time Rate is ", timerate);
console.log("1 second is %d second, about %d minutes", 1/timerate, 1/timerate/60);
(function(team, timerate) {
/* Arthur hotel escape */
console.group("2nd level: Hotel escape");
var kick = "elevator wreck";
console.log("2nd level team", team);
console.log("Time Rate is ", timerate);
console.log("1 second is %d second, about %d minutes", 1/timerate, 1/timerate/60);
(function(team, timerate) {
/* Mountain */
console.group("3rd level: Mountain's fortress");
var kick = "fortress destruction";
console.log("3rd level team", team);
console.log("Time Rate is ", timerate);
console.log("1 second is %d second, about %d minutes", 1/timerate, 1/timerate/60);
(function(team, timerate) {
console.group("4th level: the Limbo");
/* Limbo */
var kick = "skyscrapes collapse";
console.log("Limbo team", team);
console.log("Time Rate is ", timerate);
console.log("1 second is %d second, about %d minutes or %d hours",
1/timerate, 1/timerate/60, 1/timerate/3600);
console.groupEnd();
return kick;
})(team.slice(2), timerate/12); /* 4th level */
console.groupEnd();
return kick;
})(team.slice(1), timerate/12); /* 3nd level */
console.groupEnd();
return kick;
})(team.slice(1), timerate/12); /* 2nd level */
console.groupEnd();
return kick;
})(timerate/12); /* 1st level */
})();
/* now you think you have come back into reality...
* but what if you were into another closure? =)
* who knows?
*/
</script>
/*
* What is the most resilient parasite? Bacteria? A virus? An intestinal worm? An idea.
* Resilient... highly contagious. Once an idea has taken hold of the brain it's almost
* impossible to eradicate. An idea that is fully formed - fully understood - that sticks;
* right in there somewhere.
*/
@HelloGrayson
Copy link

this is sweet.

@paulmillr
Copy link

awesome!

@aranm
Copy link

aranm commented Mar 27, 2011

true geek..love it

@fcalderan
Copy link
Author

@aranm, thank you =)

@tbeseda
Copy link

tbeseda commented Mar 29, 2011

This is rad!

@sandeepjain
Copy link

Awesome!1

@milushov
Copy link

that's very cool!

@Insidexa
Copy link

Insidexa commented Aug 7, 2014

cool

@opensourcejunkie
Copy link

++

@guy16510
Copy link

Awesome.. I love it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment