javascript - 我正在尝试从堆栈创建队列,但出现错误“找不到所需的变量”
问题描述
我是编程新手,我有一个练习来为堆栈创建一个队列,但是当我验证它时给我一个错误:
“队列是一个类
TypeError:未定义不是对象(评估“Queue.prototype”)
const Stack = require('./stack');
class Queue {
constructor(){
this.first = new Stack();
this.second = new Stack();
}
add(record) {
this.first.push(record);
}
remove() {
while (this.first.peek()) {
this.second.push(this.first.pop());
}
const record = this.second.pop();
while (this.second.peek()) {
this.first.push(this.second.pop());
}
return(record);
}
peek() {
while (this.first.peek()) {
this.second.push(this.first.pop());
}
const record = this.second.peek();
while (this.second.peek()) {
this.first.push(this.second.pop());
}
return record;
}
}
module.exports = Queue;
解决方案
一个简单的例子
class Animal{
species;
constructor(){}
}
class Dog extends Animal{
name;
constructor(){
super();
}
}
let max = new Dog();
推荐阅读
- python - 为什么我的代码在控制台中运行时运行良好,但在脚本中使用时运行良好?
- machine-learning - 为什么我的机器学习算法会卡住?
- javascript - 可以使用具有真假键或逻辑运算符的对象而不是单个 if else 来降低圈复杂度吗?
- python - BeautifulSoup 中的 find_all() 方法返回空列表
- dotnetnuke - 是否可以在同一 DNN 实例上的门户之间共享 2SXC 内容模块?
- asp.net-core - 动态参数在 Put 方法中不起作用
- java - 使用 EasyMock 在异常后执行断言
- file - 如何在谷歌驱动器中移动快捷方式
- kubernetes - 如何在 Kubernetes Persistent 卷中声明和配置 Bitnami Docker Discourse 数据?
- r - 使用 rvest 抓取类似名称的表