Skip to content

Instantly share code, notes, and snippets.

@stdclass
Forked from 140bytes/LICENSE.txt
Created September 1, 2011 10:50
Show Gist options
  • Save stdclass/1185928 to your computer and use it in GitHub Desktop.
Save stdclass/1185928 to your computer and use it in GitHub Desktop.
Simple Loop
function( iterations, fn, context, original ){
original = iterations;
while( iterations-- )
fn.call( context || this, original - iterations );
}
function(i,f,c,o){o=i;while(i--)f.call(c||this,o-i)}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "simpleLoop",
"description": "Simple Loop Function.",
"keywords": [
"loop"
]
}
<!DOCTYPE html>
<html>
<head>
<title>Loop</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>div {font-size: 300%}</style>
</head>
<body>
<div>Expected: <b>12345</b></div>
<div>Result: <b id="result"></b></div>
<script>
var times = function(i,f,c,o){o=i;while(i--)f.call(c||this,o-i)}
times( 5, function( i ){
this.innerHTML += i;
}, document.getElementById("result"));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment