JSFiddle

  • Millionth Prime - chunked code

    Computes the millionth prime using closures and chunked code.

    document.getElementById("go").onclick = function() {
        var n = 2,
            count = 0;
        var findMore = function() {
            Find: for (; true; n += 1) {
                for (var ...
  • Pi Estimator #9 is the latest revision

    Illustration of the "dart-throwing" pi estimator.

    /*
     * Does a running approximation of pi by the famous dart throwing
     * algorithm.  Generates 1000 batches of 1000 random points, with ...
  • JQuery Tic Tac Toe #465 is the latest revision

    A simple tic-tac-toe game, using JQuery.

    /*
     * A complete tic-tac-toe widget, using JQuery.  Just include this 
     * script in a browser page and play.  A tic-tac-toe game will ...
  • Demo of accordion-like behavior in JQuery #17 is the latest revision

    A trivial JQuery-based fiddle showing how nested lists can collapse and expand by clicking on elements in the outer list.

    $("ul ul").hide("slow");
    $(".country").click(function() {
        $("ul ul:not(:hidden)").hide("slow");
        $(this).next().show("slow");
    });
  • 4 x 4 Tic Tac Toe #14 is the latest revision

    A trivial 4 x 4 tic tac toe game, using only regular JavaScript events.

    /*
     * A complete 4 x 4 tic-tac-toe widget.  Just include this script in a
     * browser page and play.  A tic-tac-toe game ...
  • Tic Tac Toe #662 is the latest revision

    A simple tic-tac-toe game, following the define-all-variables-at-the-top-of-each-function policy.

    /*
     * A complete tic-tac-toe widget.  Just include this script in a
     * browser page and enjoy.  A tic-tac-toe game will be included ...
  • An illustration of "private" variables : non-constructor version

    A small example of a data type with a "property" that can only be accessed via methods.

    /*
     * A simple sequence data type, illustrating "private" storage.
     * The advantage is that once a sequence is created via the
     * invocation ...
  • An illustration of "private" variables : constructor version

    A small example of a data type with a "property" that can only be accessed via methods.

    /*
     * A simple sequence data type, illustrating "private" storage.
     * The advantage is that once a sequence is created via "new
     * Sequence ...
  • Inheritance

    An approach to JavaScript inheritance in which type objects are prototypes and creation functions are properties just like other methods.

    /*
     * A person datatype.
     */
    
    var Person = {};
    
    Person.create = function (name, birthdate) {
        var person = Object.create(this);
        person.name = name;
        person.birthdate ...
  • ECMAScript Globals

    An experiment to see whether the global variables of ECMAScript are reassignable.

    /*
     * Hackish little script to see which of ECMAScript globals are writable
     * and which are not.  This script needs to be ...