每次我在JavaScript中声明一个回调时,必须手动设置对象的范围是令人沮丧的,但这是生活中的事实.我想知道我是否可以通过传递[mycallback] .apply作为回调,并将范围对象作为参数来实现,如下所示:
var f = function() { console.log(this.x); };
var o = {x: 3};
setTimeout(f.apply, 1000, o);
Run Code Online (Sandbox Code Playgroud)
据我所知,这应该用o作为范围调用f,但是Chrome给了我"未捕获的TypeError:Function.prototype.apply在[object DOMWindow]上被调用,它是一个对象,而不是一个函数".为什么这不起作用?
我的应用程序病毒式传播(yay!),并且在启动时为所有运行iOS 11的用户(boo!)发生硬崩溃.但是,当我使用XCode 9 beta(1和2)构建和运行它时,它在模拟器和手机上都能正常工作.
由于XCode 8(产生破坏的版本)无法调试iOS 11设备,并且XCode 9无法复制崩溃,因此似乎没有办法测试潜在的修复,除了将它们放在TestFlight上.即使我这样做,也无法将其连接到XCode 8调试器.有没有更简单的方法在XCode 8上调试iOS 11?谢谢!
(好奇的是,崩溃发生在UITableView._endCellAnimation- 关于__exceptionPreprocess的事情.这是片段:
let task = ItemSource.sharedSource.getRandomItems(10)
task.continueWith(
Executor.mainThread,
continuation: {
(task: Task<[Item]>) in
let nouns: [Item] = task.result!
self.controller.tableView.beginUpdates()
var indexPaths = [IndexPath]()
for noun in nouns {
indexPaths.append(self.append(noun))
}
self.controller.tableView.insertRows(at: indexPaths, with: .none)
self.controller.tableView.endUpdates() <-- Crashes here
}
)
Run Code Online (Sandbox Code Playgroud)