如何在 module.exports 中 运行 属性?
how to run property in module.exports?
我需要运行 y in x 属性,但是我得到一个错误,请帮助.
lang-js:
module.exports = {
x: () => {
this.y("hello world");
},
y: (text) => {
console.log(text);
},
};
P.S。我是菜鸟)
这个有效:
module.exports = {
x: () => {
module.exports.y("hello world");
},
y: (text) => {
console.log(text);
},
};
这也有效:
module.exports = {
x: function () {
this.y("hello world");
},
y: (text) => {
console.log(text);
},
};
注意第二个例子:它不是箭头函数。箭头函数在 this
方面的行为不同
我是这样做的:
const _something = {
x: () => {
_something.y("hello world");
},
y: (text) => {
console.log(text);
},
};
module.exports = _something;
我需要运行 y in x 属性,但是我得到一个错误,请帮助.
lang-js:
module.exports = {
x: () => {
this.y("hello world");
},
y: (text) => {
console.log(text);
},
};
P.S。我是菜鸟)
这个有效:
module.exports = {
x: () => {
module.exports.y("hello world");
},
y: (text) => {
console.log(text);
},
};
这也有效:
module.exports = {
x: function () {
this.y("hello world");
},
y: (text) => {
console.log(text);
},
};
注意第二个例子:它不是箭头函数。箭头函数在 this
我是这样做的:
const _something = {
x: () => {
_something.y("hello world");
},
y: (text) => {
console.log(text);
},
};
module.exports = _something;