var aaaa = (function () { // this funciton is only ever called once
var data =Object.create(null); // so this object only gets created once in this scope
return function (k) { //we return this function to be the value of aaaa
if (data.interval) clearInterval(data.interval); // check if there is a interval already set and remove if there is
document.body.appendChild(document.createElement('br'));
data.function = function () {
document.body.appendChild(document.createTextNode(k));
};
data.function(); // i put this here to make it run as soon as its created rather than waiting for the first interval to tick
data.interval = setInterval(data.function, 100);
}
}());
setTimeout(function () { // this is just a function executed after 2 seconds
aaaa('test2 ');
}, 2000);
aaaa('aaaa'); // happens instantly
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.