【问题标题】:Uncaught TypeError: Super expression must either be null or a function, not undefined (React.js, Flux, ES6)Uncaught TypeError: Super expression must be null or a function, not undefined (React.js, Flux, ES6)
【发布时间】:2016-12-27 18:34:05
【问题描述】:

我一直在将一个简单的 React 项目从 ES5 转换为 ES6, 7 但我遇到了问题。打开 index.html 时出现此错误:

我研究了一些常见的修复方法:

  • 更新反应

(15 应该有完整的 ES6 支持吗?)

  • 导入或循环依赖中的拼写错误

resultConstants.js

export const RESULTS = {
  RECEIVED_SEARCH: "RECEIVED_SEARCH",
  RECEIVED_RESULTS: "RECEIVED_RESULTS"
};

dispatcher.js

import { Dispatcher } from 'flux';

const AppDispatcher = new Dispatcher();

export default AppDispatcher;

但我还没有真正看到这个问题。这是导致问题的商店。

import AppDispatcher from '../dispatcher/dispatcher';
import { RESULTS } from '../constants/resultConstants';
import { FluxStore } from 'flux';

let _query = 'restaurant',
    _results = [];

const _mapOptions = {
  ...
};

class ResultStore extends FluxStore {
  query() {
    return _query;
  }

  mapOptions() {
    return _mapOptions;
  }

  all() {
    return _results.slice(0, 9);
  }

  __onDispatch(payload) {
    switch(payload.type) {
      case RESULTS.RECEIVED_SEARCH:
        _resetQuery(payload.search.query)
        _resetCenter(payload.search.center);
        resultStore.__emitChange();
        break;
      case RESULTS.RECEIVED_RESULTS:
        _resetResults(payload.results);
        resultStore.__emitChange();
        break;
      default:
        return;
    }
  }
}

function _resetQuery (query) {
  _query = query;
}

function _resetCenter (center) {
  _mapOptions.center = center;
};

function _resetResults (results) {
  _results = results;
};

export const resultStore = new ResultStore(AppDispatcher);

即使我包含这段代码的 sn-p 也要清楚:

constructor() {
  super();
}

它仍然会出现这个错误。

问题

  1. 出现此错误的其他一些原因是什么?
  2. 我的 ES6 怎么样? (赞赏有建设性的批评)

【问题讨论】:

标签: javascript reactjs ecmascript-6 flux


【解决方案1】:

显然,从不存在的类扩展类时没有错误。 因此,当调用 super 但没有父级时,会出现此错误:Uncaught TypeError: Super expression must be null or a function, not undefined.

通常是由于扩展了一个您没有完全加载的类,或者由于拼写错误或由于顺序(扩展类必须写在扩展类下面)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-17
    • 2015-07-18
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    • 2019-06-18
    • 1970-01-01
    相关资源
    最近更新 更多