首页 > 解决方案 > 这是什么 JS 语法,它是什么意思?

问题描述

首先,很抱歉这个多余的问题,只是还没有找到合适的方法来问这个问题。我正在查看一个使用 React-router 保护路由的视频,当时视频中的家伙写了这样的内容:

class Auth {
  constructor() {
    this.authenticated = false;
  }

  login(cb) {
    this.authenticated = true;
    cb();
  }

  logout(cb) {
    this.authenticated = false;
    cb();
  }

  isAuthenticated() {
    return this.authenticated;
  }
}

这是让我感到困惑的一点:

login(cb) {
  this.authenticated = true;
  cb(); // What syntax is this???
}

这到底是做什么的?是否应该将函数作为参数调用她?提前感谢您的帮助!

标签: javascriptmethodssyntax

解决方案


推荐阅读