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){返回{
并以}结束