我试图实现一个向用户"输入"消息的功能.像"T"之类的东西 - 等待 - "Th" - 等待 - "Tha"...我想出了这个功能,但它会等待然后立即更新所有字母(而不是单独更新):
var tu = 'Thank you'
var timing = 1000
for (var i=0; i<=tu.length; i++) {
setTimeout(function (){input.text(tu.slice(0, i))}, timing)
timing = timing + 1000
}
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做(不要笑),它的工作..
setTimeout(function (){input.text('t')}, 400)
setTimeout(function (){input.text('th')}, 800)
setTimeout(function (){input.text('tha')}, 3000)
setTimeout(function (){input.text('than')}, 4000)
setTimeout(function (){input.text('thank')}, 5000)
setTimeout(function (){input.text('thank ')}, 6000)
setTimeout(function (){input.text('thank y')}, 7000)
setTimeout(function (){input.text('thank yo')}, 8000)
setTimeout(function (){input.text('thank you')}, 9000)
Run Code Online (Sandbox Code Playgroud)
任何人都可以阐明为什么循环的行为与我的剪切粘贴工作不同?
我正在努力整合代码库(将qsort compar函数移动到新的标头/库,以便可以在不复制/意大利面的情况下共享它),并注意到在此过程中出现了一些奇怪的情况。
这是一个示范性清单:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/** One record has three fields.
* Each field contains a NULL terminated string of length at most 7 characters. */
typedef char Record[3][8];
int main(void)
{
Record database[5] = {0};
strcpy(database[0][0], "ZING");
strcpy(database[0][1], "BOP");
strcpy(database[0][2], "POW");
strcpy(database[1][0], "FIDDLY");
strcpy(database[1][1], "ECHO");
strcpy(database[1][2], "ZOOOM");
strcpy(database[2][0], "AH");
strcpy(database[2][1], "AAAAA");
strcpy(database[2][2], "AH");
strcpy(database[3][0], "BO");
strcpy(database[3][1], "DELTA");
strcpy(database[3][2], "FO");
strcpy(database[4][0], "FRRING");
strcpy(database[4][1], "CRASH");
strcpy(database[4][2], "FOO");
//(gdb) ptype record_compare_field_1
//type = int (char (*)[8], …Run Code Online (Sandbox Code Playgroud)