I am baffled by this code as well, not my doing. My take on it would be to split the library into one js file and one c++ file. I think however this would be scope of different pull requests. :) This code would greatly need proper testing before any rewrite as well.