First try at a JS version.