[英]how to call a function inside another function
I'm trying to call a function inside another function in javascript, actually trying to call populateCurrencies()
inside startApp()
.我试图在 javascript 中的另一个函数中调用一个函数,实际上是在
startApp()
调用populateCurrencies()
startApp()
。 What am I doing wrong?我究竟做错了什么?
const startApp = () => {
const populateCurrencies = ();
function populateCurrencies() {
alert(return this.option.value + " " + this.option.textContent);
}
const startApp = () {};
You are using a invalid syntax.您正在使用无效的语法。
You declare functions like this (with arrow function expression).您可以像这样声明函数(使用箭头函数表达式)。
const myFunc = () => {
// Code to run here...
}
And you call your function like this.你这样调用你的函数。
myFunc();
Not const myFunc = () {};
不是
const myFunc = () {};
like it is in your example.就像在你的例子中一样。
Also, const is a constant, you can't have multiple constants with the same name, so that's an error as well.另外,const 是一个常量,不能有多个同名的常量,所以这也是一个错误。 And if you want to reassign values to a variable you have to use
let
instead.如果你想给一个变量重新赋值,你必须改用
let
。 But that's beside the point since you won't need those extra variable declarations that you have now when you call the functions.但这是无关紧要的,因为在调用函数时您将不需要现在拥有的那些额外的变量声明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.