我已经将一个简单的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);
即使我包含这段代码,也要清楚:
constructor() {
super();
}
它仍然会出现此错误。
问题
答案 0 :(得分:0)
显然,从不存在的类扩展类时,没有错误。 所以当调用超级但没有父级时会出现此错误:未捕获的TypeError:超级表达式必须为null或函数,而不是未定义。
通常是通过扩展一个你没有完全加载的类,或者是由于拼写错误或者由于序列而引起的(扩展类必须写在扩展类下面)