[英]how to run property in module.exports?
I need to run y in x property, but I get an error, pleases help.我需要在x属性中运行y ,但出现错误,请帮忙。
lang-js :语言js :
module.exports = {
x: () => {
this.y("hello world");
},
y: (text) => {
console.log(text);
},
};
PS I am noob) PS我是菜鸟)
This one works:这个有效:
module.exports = {
x: () => {
module.exports.y("hello world");
},
y: (text) => {
console.log(text);
},
};
This also works:这也有效:
module.exports = {
x: function () {
this.y("hello world");
},
y: (text) => {
console.log(text);
},
};
Note in the second example: it's not an arrow function.请注意第二个示例:它不是箭头函数。 Arrow functions behave differently in regards to
this
箭头函数在
this
方面表现不同
I do it like this:我这样做:
const _something = {
x: () => {
_something.y("hello world");
},
y: (text) => {
console.log(text);
},
};
module.exports = _something;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.