如何在 Javascript 中调用函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18258579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call a function in Javascript
提问by Timothy Armoo
I am new to programming-and using codeademy to help with that so pardon me if this question is a bit of an obvious one. I mainly want to be able to call a function. I have copy and pasted the code academy stuff below and I mainly want to know what I have to do to "call the greeting function". If you could explain exactly what to do any why, that would be great.
我是编程新手 - 并使用 codeademy 来帮助解决这个问题,如果这个问题有点明显,请原谅我。我主要希望能够调用一个函数。我已经复制并粘贴了下面的代码学院的东西,我主要想知道我必须做什么才能“调用问候功能”。如果你能准确地解释为什么要做什么,那就太好了。
Below is the greeting function!
// See line 7
// We can join strings together using the plus sign (+)
// See the hint for more details about how this works.
var greeting = function (name) {
console.log("Great to see you," + " " + name);
};
// On line 11, call the greeting function!`
回答by
To call the greeting function this is all you need to do:
要调用问候功能,您只需要执行以下操作:
greeting("My Name"); // will call the function and produce "Great to see you, My Name");
回答by Matt Bryant
In javascript you call a function like this:
在 javascript 中,你调用这样的函数:
greeting("your name here");
greeting("your name here");
In general, if you have a function, the syntax is function(argument1, argument2, ...);
一般来说,如果你有一个函数,语法是 function(argument1, argument2, ...);
回答by user2502227
these are the basic.by simple efforts on Google you can find out the answer but anyways, you can call your function like this .
这些是基本的。通过在 Google 上的简单努力,您可以找到答案,但无论如何,您可以像这样调用您的函数。
greeting("your name");
回答by Deneb Shah
I got it. Now i know how to call a function. I got my answer right.
我知道了。现在我知道如何调用函数了。我得到了正确的答案。
var greeting = function (name) {
console.log("Great to see you," + " " + name);
};
// On line 11, call the greeting function!
var greeting = function (name) {
console.log("Great to see you," + " " + "Deneb");
};
greeting("Deneb");
To call a function we always need to type the function like"Greeting","myUser" etc and then give it the function parameter. This is what i did.
要调用函数,我们总是需要键入函数,如“Greeting”、“myUser”等,然后给它函数参数。这就是我所做的。