如何控制台记录答案而不是整个函数(Javascript,ES6)
How to console log the answer instead of whole function (Javascript, ES6)
我正在编写一些 ES6 代码,我想 console.log 或 document.write 我的函数的答案。当我尝试这样做时,它会写入整个函数。有没有简单的方法来做到这一点?
const stats = {
max: 56.78,
standard_deviation: 4.34,
median: 34.54,
mode: 23.87,
min: -0.75,
average: 35.85
};
const half = ({max, min}) => (max+min) / 2.0;
document.write(half)
您只需使用括号调用函数(并将 stats
对象作为参数传递):
const stats = {
max: 56.78,
standard_deviation: 4.34,
median: 34.54,
mode: 23.87,
min: -0.75,
average: 35.85
};
const half = ({max, min}) => (max+min) / 2.0;
document.write(half(stats))
我正在编写一些 ES6 代码,我想 console.log 或 document.write 我的函数的答案。当我尝试这样做时,它会写入整个函数。有没有简单的方法来做到这一点?
const stats = {
max: 56.78,
standard_deviation: 4.34,
median: 34.54,
mode: 23.87,
min: -0.75,
average: 35.85
};
const half = ({max, min}) => (max+min) / 2.0;
document.write(half)
您只需使用括号调用函数(并将 stats
对象作为参数传递):
const stats = {
max: 56.78,
standard_deviation: 4.34,
median: 34.54,
mode: 23.87,
min: -0.75,
average: 35.85
};
const half = ({max, min}) => (max+min) / 2.0;
document.write(half(stats))