你怎么以一种难以注意和修复的方式恶作剧的同事或朋友呢?最好是在JavaScript中,而不必安装任何程序.
我有一天在编程游戏时遇到了这个错误:
var foo = function() { alert("Hello, World!"); }
foo[0] = "Zero";
foo[1] = "One";
foo[2] = "Two";
foo[3] = "Three";
foo(); // Alerts "Hello, World!"
alert(foo[2]); // Alerts "Two"
Run Code Online (Sandbox Code Playgroud)
为什么JavaScript允许你这样做?这是一个小故障吗?
我有以下代码生成HTTP请求,然后将结果输出到UITextView:
@IBOutlet var echoLog: UITextView!
@IBAction func sendEcho(sender: AnyObject) {
let callback = { (textString: String) -> Void in
self.echoLog.text = textString // App crashes here :(
}
HTTPRequest("http://localhost/echo", ["echo": "Echo!"], callback)
}
Run Code Online (Sandbox Code Playgroud)
但是,当我调用sendEcho应用程序崩溃时出现此错误:
2014-07-28 20:58:22.218 AppName[10463:144343] *** Assertion failure in void _UIPerformResizeOfTextViewForTextContainer(NSLayoutManager *, UIView<NSTextContainerView> *, NSTextContainer *, NSUInteger)(), /SourceCache/UIFoundation_Sim/UIFoundation-364/UIFoundation/TextSystem/NSLayoutManager_Private.m:1547
2014-07-28 20:58:22.231 AppName[10463:144343] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!'
*** First throw call stack:
(
0 CoreFoundation 0x00496ca6 __exceptionPreprocess …Run Code Online (Sandbox Code Playgroud)