是否可以使用Qt::ApplicationState::ApplicationActive
而不是Connections {
target: something_but_what
onApplicationStateChanged: {
console.log("State changed", state)
}
}
将函数推送到数组。我正在看的代码是:
var
答案 0 :(得分:1)
您可以将其放入https://babeljs.io/repl/并查看转换为的内容。最简单的方法是使循环体成为一个接受所有循环变量作为参数的函数:
function slideRightLoop(n, work) {
var next = (n + 1 < 5) ? n + 1 : 1;
var el = document.querySelector(`.position_${n}`);
var change = function change () {
el.classList.add(`position_${next}`);
el.classList.remove(`position_${n}`);
}
work.push(change);
}
function slideRight() {
var work = [];
for (var n = 1; n < 5; n++) {
slideRightLoop(n, work);
}
work.forEach(function (n) {
return n();
});
}
答案 1 :(得分:0)
要使用var
执行您想要的操作,您可以使用临时函数围绕n
和next
值创建闭包。
我稍微更改了代码以留下有意义的部分
function slideRight() {
let work = [];
for (var n = 1; n < 5; n++) {
var next = (n + 1 < 5) ? n + 1 : 1;
let change = function(next, n){
return function change () {
console.log(next, n)
}}
work.push(change(next, n));
}
work.forEach(function (n) {
return n();
});
}
slideRight()
这应该输出所需的值