Python meets CGI

JavaScript: Elements of Programming

Useful python documents

Types of JavaScript

Arrays and functions are considered to be objects.

Values returned by typeof

Getting started

Simple HTML for JavaScript

<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Program X</title>
</head>
<body>
<h1>Program X</h1>
<pre>
<script src="programX.js">
</script>
</pre>
</body>
</html>

Simple JavaScript

document.writeln('Program X') ;

Simple interaction

Functions

All the hard stuff

An illustration of an anonymous and inner function that requires a closure.

function curryadd(m) {
    return function(n) { return m + n ; } ;
}

Normal factorial

function fact(n) {
    if (!n) {
	return 1 ;
    } else {
	return n*fact(n-1) ;
    }
}

An oddly non-recursive factorial

// Example from http://amix.dk/blog/post/19239
function facMaker(fn) {
    return function(n) {
        return n == 0 ? 1 : n * fn(fn)(n - 1);
    }
}

document.writeln(facMaker(facMaker)(10)) ;

An even odder non-recursive factorial

function Y(dn) {
    return function(fn) {
        return fn(fn);
    }(function(fn) {
	    return dn(function(x) {
		    return fn(fn)(x);
		});
	});
}

function fac4Y(fn) {
    return function(n) {
	return n == 0 ? 1 : n * fn(n - 1);
    }
} ;

document.writeln(Y(fac4Y)(10)) ;