有没有一个shorthand多次赋值window[functionName] = functionName?
Is there a shorthand to assign window[functionName] = functionName many times?
我有
window.getTask = getTask
window.postTask = postTask
window.logIn = logIn
我正在寻找一种 shorthand 方法来做到这一点。像 window[name] = [postTask, getTask, logIn]
这样的东西是否存在使用现代 javascript 的东西?
您可以使用 Object.assign
and shorthand property names 做这样的事情:
Object.assign(window, {
getTask,
postTask,
logIn,
// ... and so on
});
我有
window.getTask = getTask
window.postTask = postTask
window.logIn = logIn
我正在寻找一种 shorthand 方法来做到这一点。像 window[name] = [postTask, getTask, logIn]
这样的东西是否存在使用现代 javascript 的东西?
您可以使用 Object.assign
and shorthand property names 做这样的事情:
Object.assign(window, {
getTask,
postTask,
logIn,
// ... and so on
});