Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

samtregar (2699)

samtregar
  (email not shown publicly)
http://sam.tregar.com/

Journal of samtregar (2699)

Monday December 27, 2004
03:27 PM

On Becoming a Javascript Expert

[ #22473 ]
It's been a long time coming but I think I'm actually starting to get comfortable coding in Javscript. I'm working on a very complicated edit screen with lots of automated fields and behaviors so I'm getting a lot of practice. O'Reilly's Dynamic HTML book has been a great help. I generally find it more useful than their Javascript book. The coverage of cross-browser differences is better and the coverage is wider, covering all of CSS and HTML.

I've definitely made the transition from grudging Javascript hacker to coder: I'm building reusable tools. To whit, here's a very helpful logging utility that shows messages in a separate window refreshed on each hit:

var log_span;
function log(msg) {
    if (!log_span) {
        var log_window = window.open("", "log", "status,width=700,height=300");
        log_window.document.write('<h2>JS Log</h2><span id=log></span>');
        log_window.document.close();
        log_span = log_window.document.getElementById("log");
        log_span.innerHTML = "";
    }
    var d = new Date();
    log_span.innerHTML += "[" + d.toLocaleString() + "] " +
                          msg + "<br>";
}

Before I came up with that one I was using alert() for confessional debugging which is a complete pain.

I've also learned how to create my own classes in Javascript which allows for much cleaner code than my previous practice. Of course, Javascript doesn't really have classes, it uses prototype-based inheritence instead. It's weird by servicable once I got the syntax right.

Another big factor in my increasing Javascript confidence is the Emacs ecmascript-mode I found on the EmacsWiki. It looks and feels so much like cperl-mode that I can't help but feel at home.

-sam

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Hey, looks familiar:

    function logAdd(msg, which) {

        var name = which != null ? which : "Log"

        var l = document.getElementById(name);

        var date = new Date();

        var string = date + ": " + msg + "<br>" + l.innerHTML

        l.innerHTML = string.substr(0, 4000)

    }

    It's also really useful for debugging long running flash movies (In our case from a couple of weeks, to a couple of years). The substr helps keep the ram usage down :)

    • You have flash movies with an uptime > a year?
      • Yes, we will use it for distributed "live" display of a lottery, that has draws every 3 minutes on terminals distributed throughout northern Germany. Sometimes the terminals might be turned off at night, but other terminals might run basically forever. We have zero leakage, so there is really to reason to ever restart the thing.

  • var log_window = window.open("", "log", "scrollbars=1,statusbar=0,resizable=1,width=700,height=300");

    That way you can scroll and/or resize the log window as needed.

  • my deepest sympathy.
  • var _js_log = {
        logwin: null,
        append: function( elt, tagname ) {
            var doc = this.logwin.document;
            return elt.appendChild( doc.createElement( tagname ) );
        },
        appendtext: function( elt, tagname, text ) {
            var doc = this.logwin.document;
            return this.append( elt, tagname ).appendChild( doc.createTextNode( text ) );
        },
        msg: functi