javaScript implementation