Skip to Main Skip to Footer
Back to Header Skip to Footer
← zurück zum Blog

The Tale Of The Little Red Riding Hood Told By A Software Developer

Veröffentlicht: 15.12.2016
Anzahl Wörter: 286
Lesedauer: 1 min

What happens when a software developer tells her kid a bedtime story?

For all those who do not “speak” JavaScript I included a little bit of comments. Enjoy.

function TheTellOfRedRidingHood()
{
    var RedRidingHood = new Person();
    RedRidingHood.cloth = { 
        type: 'hood',
        color: 'red'
    };

    var mom = RedRidingHood.getMother();

    var basket = mom.pack(['wine', 'bread', 'cake']);

    var granny = mom.getMother();

    granny.adress = 'in the woods';

    // after this continue with Person.visit
    RedRidingHood.carry(basket).visit(granny);
}

Person.visit = function(whom)
{
    var RedRidingHood = this;

    if (!whom)
        return;

    var granny = whom;

    var forest = new Woods();

    var wolf = new Animal();

    RedRidingHood.go(forest).meet(wolf).chat(wolf, tellTooMuch);

    // after this continue with Animal.visit
    wolf.visit(granny).waitFor(RedRidingHood);

    // after this continue with Person.ask
    RedRidingHood
    .ask(wolf, 'What big eyes you have!')
    .ask(wolf, 'What large hands you have!')
    .ask(wolf, 'What a terrible big mouth you have!')
    .scream();

    wolf.eat(RedRidingHood);

    var huntsman = new Person();

    huntsman.open(wolf).save([RedRidingHood, granny]);

    return RedRidingHood;
};

Person.ask = function(whom, what)
{
    if (!whom || !what)
        return null;

    // after this continue with Animal.answer
    whom.answer(what);

    return this;
};

Animal.visit = function(whom)
{
    var wolf = this;

    if (!whom)
        return;

    var granny = whom;

    wolf.eat(granny);
};

Animal.answer = function(question)
{
    if (!question)
        return '???';

    if ('What big eyes you have!' === question)
    {
        return 'All the better to see you with';
    }
    else if ('What large hands you have!' === question)
    {
        return 'All the better to hug you with';
    }
    else if ('What a terrible big mouth you have!' === question)
    {
        return 'All the better to eat you with';
    }
};

Yes, I know we software developers are considered to by … uhm … nerdy. Then again you know every now and then I need to be able to do crazy things to stay sane.

Yours

Mira Alexander

Sie haben eine Anmerkung oder eine Anregung zu diesem Artikel? Ich freue mich über Ihren Kommentar.