Skip to content

Instantly share code, notes, and snippets.

@seantunwin
Last active December 18, 2015 03:19
Show Gist options
  • Select an option

  • Save seantunwin/5717006 to your computer and use it in GitHub Desktop.

Select an option

Save seantunwin/5717006 to your computer and use it in GitHub Desktop.
This is the original script that compelled me to make a modular version in order to be reusable - https://github.com/seantunwin/chardelay.js | View the project: http://seantunwin.github.io/chardelay.js
/**
* This is the original script that compelled me to make a modular version in order to be reusable
* - Repo: https://github.com/seantunwin/chardelay.js
* - View the project: http://seantunwin.github.io/chardelay.js
**/
/* Set Array */
var arr = [1,2,3,4];
/* Create <p> element */
var el = document.createElement('p');
/* Write text inside <p> tag */
function writeIt(y) {
el.innerHTML += arr[y] + '<br />';
}
/* Initializer */
function init() {
/* Set Timeout Interval */
var time = 1000;
/* Attach <p> tag to document */
document.body.appendChild(el);
/* Loop through Array */
for (var i = 0; i < arr.length; i++) {
/* Anonymous IIFE passing vars i and time */
(function(x, t){
/* Invoke delay */
setTimeout(function(){
/* Call write function */
writeIt(x);
},x * time); /* multiply to keep consistant interval on each loop*/
})(i, time);
}
}
/* Start */
init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment