Implementing Matt in javaScript