Wednesday, December 26, 2012

JS Study

========
Closure
========
<html>
<head>
<title>Closure</title>
<script>
var fade = function(node) {
        var level = 0; // Closure element

        // step is closure element
        var step = function() {
                var hex = level.toString(16);
               
                // node is closure element
                node.style.backgroundColor = '#' + hex + hex + hex + hex + hex + hex;
                if (level < 15) {
                        level++;
                        setTimeout(step, 1000);
                }
        };

        setTimeout(step, 100);
};

var quo = function(stat) {
        return {
                getStatus: function() {
                        return stat;
                }
        };
};

var a = quo("Good");
document.writeln(a.getStatus());
fade(document.body);
</script>
</head>
<body>
</body>
</html>

No comments: