Perhaps you could change requireXhr method to return the new _XhrHandler instead of assigning it to xhrHandler, and change this if/else to this.xhrHandler = args.xhrHandler || requireXhr(args.endpoint);