Nursery Rhyme Code Poem [JavaScript]

(function()
{
    function BlindMouse() {}
    BlindMouse.prototype.tail = true;
    BlindMouse.prototype.run = function(after) {};
 
    function Mice(mouse1, mouse2, mouse3)
    {
        this.mice = [];
        this.mice.push(mouse1, mouse2, mouse3);
        this.declare = function()
        {
            return this.mice.length + ' Blind Mice';
        };
        this.run = function(after)
        {
            for(var j=0,k=this.mice.length;j<k ;j++) {
                this.mice[j].run(after);
            }
        };
        this.cutOff = function(prop, weapon)
        {
            for(var j=0,k=this.mice.length;j<k;j++) {
                this.mice[j][prop] = false;
            }
        };
    }
 
    var mice = new Mice(new BlindMouse(), new BlindMouse(), new BlindMouse());
    alert(mice.declare());
    alert(mice.declare());
 
    function seeHow(they, func)
    {
        they[func]();
    }
 
    seeHow(mice, 'run');
    seeHow(mice, 'run');
 
    var farmersWife = function()
    {
        var weapon = 'Carving Knife';
        return {
            cutOff: function(creatures, prop)
            {
                creatures.cutOff('tail', weapon);
            }
        }
    }();
 
    mice.run(farmersWife);
 
    farmersWife.cutOff(mice, 'tail');
 
    function haveYouSeen(obj, timeSpan)
    {
        return true;
    }
 
    if(haveYouSeen('Such a Thing', 'Your Life')) {
        alert('as ' + mice.declare() + '?');
    }
}());

The above code poem is released under the BSD license. To use in production environment without error, please enclose with a try-catch block. Obviously I’m kidding, don’t use this code. Not even for enterprise software.

This entry was posted in Artistic, JavaScript and tagged , . Bookmark the permalink. Both comments and trackbacks are currently closed.
  • If you found this article useful, you should subscribe to my feed (or get an e-mail). I'm also on Twitter and GitHub.
  • About the Author

    Zach Leatherman is a Professional Front End Engineer. He loves building for the web, and has been contributing to the community through his blog since February 2007. Despite his propensity for software, he has a Bachelors degree in Computer Engineering and is currently on the User Experience Team at Union Pacific Railroad. The views expressed on this website do not represent the views of his employer.

    He enjoys spending time with his beautiful wife Traci and their two Great Danes, Roxie and Ella. They also have a cat, a rabbit, goldfish, and one or more tarantulas. Read more »