Back to the Future, Explained

I just watched Back to the Future. Aside from the fact the movie is awesome one thing has always bugged me. So Marty goes back in time and meets his parents, and in so doing changes their lives for the better. When he comes back to the future his parents are changed but his own memories and past are not. Which makes no sense.

Or at least, it makes no sense unless time supports closures. When Marty was created his personal history was bound to him, or at least this instance of him. Then when he goes back to the future and comes back he brings his scope or history with him.

Explanation in javascript: (this will run in Rhino)

var dadWriter = false;

var marty = function(){
    var dad = dadWriter;

    function isDadWriter(){
        return dad;
    }

    return {

        isDadWriter: function(){
            return isDadWriter();
        }

    };

}();

print(marty.isDadWriter()); //false
dadWriter = true;
print(marty.isDadWriter()); //false

2 Comments

  1. Posted 07/08/09 at 5:58 am | Permalink

    Yes, this is awesome!

    Can you supply a code sample to describe Einstein the dog?

  2. Posted 24/08/09 at 12:04 pm | Permalink

    You can do it with less code:

    var dadWriter = false;

    var marty = {
    isDadWriter : (function () {
    var dad = dadWriter;
    return function () {
    return dadWriter;
    };
    })()
    };

    print(marty.isDadWriter()); //false
    dadWriter = true;
    print(marty.isDadWriter()); //false