簡體   English   中英

未捕獲的TypeError:超級表達式必須為null或函數,且未定義(React.js,Flux,ES6)

[英]Uncaught TypeError: Super expression must either be null or a function, not undefined (React.js, Flux, ES6)

我一直在將一個簡單的React項目從ES5轉換為ES6、7,但是遇到了一個問題。 打開index.html時出現此錯誤: 在此處輸入圖片說明

我研究了一些常見的修復方法:

  • 更新React

(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);

為了清楚起見,即使我包含以下代碼段:

constructor() {
  super();
}

它仍然會出現此錯誤。

問題

  1. 出現此錯誤的其他原因有哪些?
  2. 我的ES6怎么樣? (建設性的批評表示贊賞)

顯然,從不存在的類擴展類時,沒有錯誤。 因此,當super被調用但沒有父對象時,會出現以下錯誤:Uncaught TypeError:Super表達式必須為null或函數,且未定義。

通常是由於擴展您拼寫錯誤或由於順序而導致您未加載的類引起的(擴展類必須寫在擴展類下面)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM