javascript - 为什么*不*我需要设置或读取类属性的方法?
问题描述
在将 getter 和 setter 放在一起时,我意识到它们不是必需的。
我错过了什么?如何确保当我调用属性时它们是类中的属性?
'use strict';
const { Book } = require('../app');
const { Page } = require('../page');
const { Bookmark } = require('../bookmark');
//
const chai = require('chai');
const expect = chai.expect;
it('has a bookmark', function () {
let bookmark = new Bookmark('bookmark');
bookmark.material = 'paper';
bookmark.mm='a';
expect(bookmark.mm).to.equal('a');
expect(bookmark.material).to.equal('paper');
})
#../bookmark.js
class Bookmark {
constructor(name) {
this.name = name;
}
}
exports.Bookmark = Bookmark;
解决方案
推荐阅读
- sql - SQL finding the sum of subrange of values
- flutter - 无法将flutter现有项目更改为flutter web
- javascript - Axios 取消令牌在实时搜索反应应用程序中不起作用
- html - 使范围滑块垂直
- firebase - Cloud Firestore 基于角色的访问
- javascript - 在url地址开头发送带有api的xhr
- python - PowerScan 发送蜂鸣信号
- amazon-web-services - AWS Glue 中用于历史数据的 ETL 作业
- python - 如何在 PYOMO Python 中考虑 model.Var() 的 5 个最高值进行优化
- amazon-s3 - 我需要在 s3 存储桶中配置 CORS 我拥有的代码不是有效的 JSON