Update closeAll function to ensure instance.close() can be executed without JS error

The prototype of Array may be changed by others, so at least we have to make sure the instance.close is a Function.