JavaScript implementation