When A is brought near the electroscope, the leaves of the electroscope diverge further, because A is positively charged. When A is brought near the electroscope, more negative charge starts accumulating on the disc of the electroscope by the process of induction, whereas the far end becomes more positive, so the leaves of the electroscope diverge further.
When B is brought near the electroscope, the leaves of the electroscope collapse, because B is negatively charged. When B is brought near the electroscope, the negative charge on the disc of the electroscope starts moving towards the leaves of the electroscope by the process of induction, so the leaves of the electroscope becomes less positive and collapse.