Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript返回函数语法_Javascript - Fatal编程技术网

Javascript返回函数语法

Javascript返回函数语法,javascript,Javascript,我想做一个函数,返回一些代码,我正在努力做到这一点 function getpresent (place) = { type: "single-stim", stimulus: getword(place), is_html: true, timing_stim: 250, timing_response: 2000, response_ends_trial: false, }; 这是我现在拥有的,但它不起作用。我需要像 function getpresent (p

我想做一个函数,返回一些代码,我正在努力做到这一点

function getpresent (place) = {
  type: "single-stim",
  stimulus: getword(place),
  is_html: true,
  timing_stim: 250,
  timing_response: 2000,
  response_ends_trial: false,
  };
这是我现在拥有的,但它不起作用。我需要像

function getpresent (place) = {
   RETURN [
  type: "single-stim",
  stimulus: getword(place),
  is_html: true,
  timing_stim: 250,
  timing_response: 2000,
  response_ends_trial: false,
],  
};
这只是语法问题吗?或者我所尝试的只是从根本上有缺陷?谢谢

如果您希望返回一个,那么这将起作用

function getpresent (place) {
    return {
        type: "single-stim",
        stimulus: getword(place),
        is_html: true,
        timing_stim: 250,
        timing_response: 2000,
        response_ends_trial: false
    };
}
如果您想返回一个,那么这将起作用

function getpresent (place) {
    return {
        type: "single-stim",
        stimulus: getword(place),
        is_html: true,
        timing_stim: 250,
        timing_response: 2000,
        response_ends_trial: false
    };
}

这里有很多混合语法

var getpresent = place => ({
  type: 'single-stim',
  stimulus: getword(place),
  is_html: true,
  timing_stim: 250,
  timing_response: 2000,
  response_ends_trial: false
});
注意,如果没有transpiler或支持ES6 arrow功能的浏览器,这将无法工作。我不知道你朝哪个方向走

数组(
[]
)不能像代码底部那样包含键/值对。只有对象具有键/值对(
{}


另外,
RETURN
无效,必须使用
RETURN
才能从函数返回。

这里有很多混合语法

var getpresent = place => ({
  type: 'single-stim',
  stimulus: getword(place),
  is_html: true,
  timing_stim: 250,
  timing_response: 2000,
  response_ends_trial: false
});
function getpresent(place) {
  return {
    type: "single-stim",
    stimulus: getword(place),
    is_html: true,
    timing_stim: 250,
    timing_response: 2000,
    response_ends_trial: false,
  }
}
注意,如果没有transpiler或支持ES6 arrow功能的浏览器,这将无法工作。我不知道你朝哪个方向走

数组(
[]
)不能像代码底部那样包含键/值对。只有对象具有键/值对(
{}

另外,
RETURN
无效,必须使用
RETURN
才能从函数返回

function getpresent(place) {
  return {
    type: "single-stim",
    stimulus: getword(place),
    is_html: true,
    timing_stim: 250,
    timing_response: 2000,
    response_ends_trial: false,
  }
}
或者使用ES6语法:

const getpresent = (place) => ({
  type: "single-stim",
  stimulus: getword(place),
  is_html: true,
  timing_stim: 250,
  timing_response: 2000,
  response_ends_trial: false,
});
或者使用ES6语法:

const getpresent = (place) => ({
  type: "single-stim",
  stimulus: getword(place),
  is_html: true,
  timing_stim: 250,
  timing_response: 2000,
  response_ends_trial: false,
});

删除
=

正确的函数语法:

function myFunction(param) {
    return param;  
}

删除
=

正确的函数语法:

function myFunction(param) {
    return param;  
}

你差点就成功了。你几乎拥有了它,而不是
函数getpresent(place)={
尝试
函数getpresent(place){return{
并以
}
结束,而不是
函数getpresent(place)={
尝试
函数getpresent(place){返回{
并以
}结束