新方法看不到";这";(JavaScript)

新方法看不到";这";(JavaScript),javascript,oop,object,methods,this,Javascript,Oop,Object,Methods,This,制作一个接受新方法的计算器。但当我添加一个新方法时,它并没有看到对象的“this”。为什么Console.log返回“未定义” 函数计算器(){ this.numbers=函数(){ 这个数字=2; 此参数为0.numberTwo=5; }, this.addMethod=函数(op,func){ this[op]=func(this.numberOne,this.numberTwo); //为什么日志返回“未定义”? console.log(this.numberOne); } } 让cal

制作一个接受新方法的计算器。但当我添加一个新方法时,它并没有看到对象的“this”。为什么Console.log返回“未定义”

函数计算器(){
this.numbers=函数(){
这个数字=2;
此参数为0.numberTwo=5;
},
this.addMethod=函数(op,func){
this[op]=func(this.numberOne,this.numberTwo);
//为什么日志返回“未定义”?
console.log(this.numberOne);
}
}
让calc=新计算器();
计算方法(“/”,(a,b)=>(a/b));

文件写入(计算[“/”])
在尝试调用函数之前,您没有定义
this.numberOne
this.numberTwo
。此外,您正在打印代码中从未定义的
this.one

如果您尝试了以下代码段:

函数计算器(){
this.numbers=函数(){
这个数字=2;
此参数为0.numberTwo=5;
},
this.addMethod=函数(op,func){
this[op]=func(this.numberOne,this.numberTwo);
//为什么日志返回“未定义”?
console.log(this.numberOne);
}
}
让calc=新计算器();
计算数字();
计算方法(“/”,(a,b)=>(a/b));//2/5

文件写入(计算[“/”])
在尝试调用函数之前,您没有定义
this.numberOne
this.numberTwo
。此外,您正在打印代码中从未定义的
this.one

如果您尝试了以下代码段:

函数计算器(){
this.numbers=函数(){
这个数字=2;
此参数为0.numberTwo=5;
},
this.addMethod=函数(op,func){
this[op]=func(this.numberOne,this.numberTwo);
//为什么日志返回“未定义”?
console.log(this.numberOne);
}
}
让calc=新计算器();
计算数字();
计算方法(“/”,(a,b)=>(a/b));//2/5

文件写入(计算[“/”])您的号码未初始化

你也用了这个。一个那是什么?你的意思是
numberOne

查看下面的工作代码:

函数计算器(){
这个数字=2;
此参数为0.numberTwo=5;
this.addMethod=函数(op,func){
this[op]=func(this.numberOne,this.numberTwo);
//为什么日志返回“未定义”?
console.log(this.numberOne,this.numberTwo);
}
}
让calc=新计算器();
计算方法(“/”,(a,b)=>(a/b));

文件写入(计算[“/”])您的号码未初始化

你也用了这个。一个那是什么?你的意思是
numberOne

查看下面的工作代码:

函数计算器(){
这个数字=2;
此参数为0.numberTwo=5;
this.addMethod=函数(op,func){
this[op]=func(this.numberOne,this.numberTwo);
//为什么日志返回“未定义”?
console.log(this.numberOne,this.numberTwo);
}
}
让calc=新计算器();
计算方法(“/”,(a,b)=>(a/b));

文件写入(计算[“/”])第5行输入错误:逗号应该是分号。
这个。一个
从来没有设置过,所以是的,它是未定义的,
我认为这两种方式都有效…第5行输入错误:逗号应该是分号。
这个。一个
从来没有设置过,所以是的,这是
未定义的
+goliadkin我想这两种方法都有效…这是一个打字错误。带计算数();一切都好!多谢各位!这是一个打字错误。带计算数();一切都好!多谢各位!