javascript - JS“语法错误:预期的表达式,得到'>'”对象内带有箭头函数
问题描述
所以,我试图将箭头函数分配给对象中的变量。每当我这样做时,它都会错误地说出意外的语法。我们不打算将箭头函数分配给对象内的变量吗?
class contentController{
constructor(tabs,tree){
this.tree=tree;
this.tabs=tabs;
this.tabs.addCallback(id=>this.clickTab(id));
this.tree.addCallback(id=>this.clickTree(id));
this.currentId=null;
this.currentTab=null;
this.properties=document.getElementById('category_props');
this.products=document.getElementById('category_items');
this.propform=document.getElementById('categorypropform');
this.events={
clickReset:(e)=>{this->clickReset(e)}, //does not like!
clickUpdate:(e)=>{this->clickUpdate(e)} //this either
}
this.events.clickUpdate=clickUpdate;
this.events.clickReset(1);
}
//class continues for many, many lines...
}
解决方案
您有一些语法错误,在箭头函数中您需要始终使用 =>,并且访问元素属性(例如方法(函数))的方法是使用点符号
class contentController{
constructor(tabs,tree){
this.tree=tree;
this.tabs=tabs;
this.tabs.addCallback(id=>this.clickTab(id));
this.tree.addCallback(id=>this.clickTree(id));
this.currentId=null;
this.currentTab=null;
this.properties=document.getElementById('category_props');
this.products=document.getElementById('category_items');
this.propform=document.getElementById('categorypropform');
this.events={
clickReset:(e)=>{this.clickReset(e)},
clickUpdate:(e)=>{this.clickUpdate(e)}
}
this.events.clickUpdate=clickUpdate;
this.events.clickReset(1);
}
//class continues for many, many lines...
}
推荐阅读
- php - Laravel 8 不显示新图像
- xpages - Notes 11 升级后我无法调试数据库给 apache poi 库错误
- javascript - 我可以通过 react-google-maps/api 使用 Google 地方信息吗?
- sql - 如何在 SQL 中创建包含使用 AVG() 函数的列?
- react-native - 有没有办法告诉用户他们没有可以打开文件的应用程序?
- go - http.client 中带有 Range 标头的 GzipReader 不起作用
- python - 复制 AutoKeras StructuredDataClassifier 的问题
- c# - Azure 时间戳未出现在语音转文本模型中?
- reactjs - 在 typescript 中为 JSX.Element 添加更多道具
- c++ - QT:信号/插槽连接通过 connect 或 on_