84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
例如
func hello() -> Bool { var result = false httpRequestWithCompletionHandler({ is404 in result = is404 }) return result }
这个函数的返回值永远是 false,因为 closure 是异步执行的怎么在调用这个函数的时候,得到真正的返回值呢?注: result 必须定义在函数体内,不能定义在函数体外
小伙看你根骨奇佳,潜力无限,来学PHP伐。
var result_cb = function (result) { alert(result) }; function hello(cb) { httpRequestWithCompletionHandler(is404) { cb(is404); } } hello(result_cb);
Like this?
GO lang ? Asynchronously executed functions can only obtain values through callbacks, so the results cannot be obtained directly by returning bool from hello.
Like this?
GO lang ? Asynchronously executed functions can only obtain values through callbacks, so the results cannot be obtained directly by returning bool from hello.