javascript implementation