code: function(config) {
      try {
        config = config || {};
  
        // TODO warn about setting per instance errorHandler / logger / logLevel
        if (config.errorHandler) {
          logging.setErrorHandler(config.errorHandler);
        }
        if (config.logger) {
          logging.setLogHandler(config.logger);
          // respect the logger's shouldLog functionality
          logging.setLogLevel(logging.LogLevel.NOTSET);
        }
        if (config.logLevel !== undefined) {
          logging.setLogLevel(config.logLevel);
        }
  
        try {
          configValidator.validate(config);
          config.isValidInstance = true;
        } catch (ex) {
          logger.error(ex);
          config.isValidInstance = false;
        }
  
        // Explicitly check for null or undefined
        // prettier-ignore
        if (config.skipJSONValidation == null) { // eslint-disable-line eqeqeq
          config.skipJSONValidation = true;
        }
  
        var wrappedEventDispatcher = new eventProcessor.LocalStoragePendingEventsDispatcher({
          eventDispatcher: config.eventDispatcher || defaultEventDispatcher,
        });
        if (!hasRetriedEvents) {
          wrappedEventDispatcher.sendPendingEvents();
          hasRetriedEvents = true;
        }
  
        config = fns.assignIn({}, config, {
          eventDispatcher: wrappedEventDispatcher,
          clientEngine: enums.JAVASCRIPT_CLIENT_ENGINE,
          // always get the OptimizelyLogger facade from logging
          logger: logger,
          errorHandler: logging.getErrorHandler(),
        });
  
        return new Optimizely(config);
      } catch (e) {
        logger.error(e);
        return null;
      }
    }
docs: Creates an instance of the Optimizely class
  @param  {Object} config
  @param  {Object} config.datafile
  @param  {Object} config.errorHandler
  @param  {Object} config.eventDispatcher
  @param  {Object} config.logger
  @param  {Object} config.logLevel
  @param  {Object} config.userProfileService
  @param {Object} config.eventBatchSize
  @param {Object} config.eventFlushInterval
  @return {Object} the Optimizely object