如何在另一个函数中调用一个函数?

我只想知道如何在另一个函数中调用 javascript 函数。 如果我有下面的代码,我如何调用第一个函数中的第二个函数?

function function_one()
{
alert("The function called 'function_one' has been called.")
//Here I would like to call function_two.
}


function function_two()
{
alert("The function called 'function_two' has been called.")
}
474951 次浏览

function function_one() {
function_two(); // considering the next alert, I figured you wanted to call function_two first
alert("The function called 'function_one' has been called.");
}


function function_two() {
alert("The function called 'function_two' has been called.");
}


function_one();

再多说一点上下文: 这在 JavaScript 中可以工作,因为有一个叫做“变量提升”的语言特性——基本上,可以把它想象成 变量/函数声明放在作用域的顶部(更多信息)。

function function_one() {
function_two();
}


function function_two() {
//enter code here
}

function function_one()
{
alert("The function called 'function_one' has been called.")
//Here u would like to call function_two.
function_two();
}


function function_two()
{
alert("The function called 'function_two' has been called.")
}

function function_first() {
function_last();
alert("The function called 'function_first' has been called.");
}


function function_last() {
alert("The function called 'function_last' has been called.");
}


function_first();