【发布时间】:2022-01-16 12:35:14
【问题描述】:
我对 TypeError: Cannot read properties of undefined (reading 'read') in gitlab 有点困惑。我想要以下:
函数 createCalculator() 用三个方法返回一个对象:
read (arr) 接受一个数字表并将其保存在其字段中 对象。
sum() 返回表格值的总和
mul() 返回表值的乘积
采取以下和平代码:
function createCalculator() {
let calculator = {
sum() {
return this.a + this.b + this.c ;
},
mul() {
return this.a * this.b*this.c;
},
read(arr) {
this.a = 1;
this.b = 3;
this.c = 6;
arr.push(arr);
}
};
calculator.read([1,3,6]);
console.log( calculator.sum() );
console.log( calculator.mul() );
}
let calculator;
calculator = createCalculator();
【问题讨论】:
-
你的函数没有返回任何东西,你的 read 方法也没有保存任何数组,只是分配了一些硬编码的属性。
-
我该如何解决?你能帮帮我吗?
-
这和 GitLab 有什么关系?这是否发生在某些 CI 管道中?这似乎与 GitLab 无关。
标签: javascript gitlab