/*
All texts and infos I have taken from:
'JavaScript: The Good Parts' by Douglas Crockford
*/
// closure
// inner functions have access to outer functions variables
// even iv the outer function "doesn't exist" anymore
var myObject = (function() {
var _value = 0;
return {
increment: function increment(inc) {
_value += typeof inc === 'number' ? inc : 1;
},
getValue : function getValue() {
return _value;
}
}
}());
myObject.increment(1);
// you could do this but you should not do this!
// obj._value is not the same as the private variable!!!
myObject._value = 5;
console.log(myObject.getValue());
var quo = function quo(status) {
return {
getStatus: function getStatus(){
return status;
}
}
};
var myQuo = quo("my status quo");
console.log(myQuo.getStatus());
var fade = function fade(node) {
var level = 1;
var step = function step() {
var hex = level.toString(16);
node.style.backgroundColor = '#FFFF' + hex + hex;
if (level < 15) {
level++;
setTimeout(step, 250);
}
};
setTimeout(step, 250);
};
fade(document.body);
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.