我开始学习node.js。我的模块有问题。我复制并粘贴了来自node.js文档的代码,但仍然出现错误。
/* ----------------------Addition Calculation-------------------- */
const object = require('./lib.js');
console.log(`The sum of 25 and 456 is + ${object.calculate1(25, 456)}`);
console.log(`The multipication of 25 and 2 is ${object.multiClass(25, 2)}`);
/* --------------------Circle Area Calculation-------------------- */
console.log(`The area of a circle of radius 7 is ${object.area(7)}`);
console.log(`The circumference of a circle of radius 7 is ${object.circumference(7)}`);
/* ----------------------Square Calculation-------------------- */
console.log(`The area of my square is ${object(2).area()}`);
const { PI } = Math;
exports.calculate1 = (a, b) => a + b;
exports.multiClass = (a, b) => a * b;
exports.area = r => PI * r ** 2;
exports.circumference = r => 2 * PI * r;
exports = (width) => {
return {
area: () => width ** 2
};
};
答案 0 :(得分:0)
我现在所做的更改
const object = require('./lib.js');
/* ----------------------Square Calculation-------------------- */
console.log(`The area of my square is ${object(2).area2()}`);
/* ----------------------Addition Calculation-------------------- */
console.log(`The sum of 25 and 456 is ${object.calculate1(25, 456)}`);
console.log(`The multipication of 25 and 2 is ${object.multiClass(25, 2)}`);
/* --------------------Circle Area Calculation-------------------- */
console.log(`The area of a circle of radius 7 is ${object.area(7)}`);
console.log(`The circumference of a circle of radius 7 is ${object.circumference(7)}`);
const { PI } = Math;
module.exports = width => {
return {
area2: () => width ** 2
};
};
module.exports.calculate1 = (a, b) => a + b;
module.exports.multiClass = (a, b) => a * b;
module.exports.area = r => PI * r ** 2;
module.exports.circumference = r => 2 * PI * r;