[問題] 關於Callback的Scope疑問
打給厚,大家好!
我是Javascript新手 想詢問關於js function scope的問題...
我有一個程式如下:
直接於mainLoop裡面使用show(),結果成功找到蘋果(this.apple)
http://jsfiddle.net/sakmor/4krzcs0g/9/
透過compare使用show(),結果無法到this.apple =undefined
http://jsfiddle.net/sakmor/4krzcs0g/
請問大大我要怎麼改,才能讓我透過compare()呼叫的show()可以
順利找到apple?
我稍微查了一下 是不是可以用Closure解決?
只是我不知道Closure怎麼使用.....
再請各位大大解答!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.251.182.68
※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1424927977.A.991.html
→
02/26 13:53, , 1F
02/26 13:53, 1F
→
02/26 13:53, , 2F
02/26 13:53, 2F
推
02/26 14:23, , 3F
02/26 14:23, 3F
→
02/26 14:24, , 4F
02/26 14:24, 4F
→
02/26 14:34, , 5F
02/26 14:34, 5F
→
02/26 14:34, , 6F
02/26 14:34, 6F
→
02/26 14:35, , 7F
02/26 14:35, 7F
→
02/26 14:37, , 8F
02/26 14:37, 8F
→
02/26 14:37, , 9F
02/26 14:37, 9F
→
02/26 14:37, , 10F
02/26 14:37, 10F
推
02/26 15:09, , 11F
02/26 15:09, 11F
→
02/26 16:20, , 12F
02/26 16:20, 12F
推
02/26 16:32, , 13F
02/26 16:32, 13F
→
02/26 16:32, , 14F
02/26 16:32, 14F
推
02/26 16:36, , 15F
02/26 16:36, 15F
→
02/26 16:37, , 16F
02/26 16:37, 16F
→
02/26 18:39, , 17F
02/26 18:39, 17F
→
02/26 18:47, , 18F
02/26 18:47, 18F
→
02/26 18:47, , 19F
02/26 18:47, 19F
→
02/26 18:49, , 20F
02/26 18:49, 20F
推
02/26 22:44, , 21F
02/26 22:44, 21F
→
02/26 22:46, , 22F
02/26 22:46, 22F
→
02/26 22:47, , 23F
02/26 22:47, 23F
→
02/26 22:47, , 24F
02/26 22:47, 24F
→
02/26 22:47, , 25F
02/26 22:47, 25F
→
02/26 22:48, , 26F
02/26 22:48, 26F
→
02/26 23:00, , 27F
02/26 23:00, 27F
推
02/27 10:33, , 28F
02/27 10:33, 28F
推
02/27 11:28, , 29F
02/27 11:28, 29F
推
02/27 13:40, , 30F
02/27 13:40, 30F
→
02/27 13:41, , 31F
02/27 13:41, 31F
→
02/27 13:51, , 32F
02/27 13:51, 32F
推
02/28 20:41, , 33F
02/28 20:41, 33F
→
02/28 21:45, , 34F
02/28 21:45, 34F
→
02/28 21:46, , 35F
02/28 21:46, 35F
→
02/28 21:50, , 36F
02/28 21:50, 36F
→
02/28 23:54, , 37F
02/28 23:54, 37F
→
02/28 23:55, , 38F
02/28 23:55, 38F
推
03/01 00:18, , 39F
03/01 00:18, 39F
→
03/01 00:29, , 40F
03/01 00:29, 40F
→
03/01 00:31, , 41F
03/01 00:31, 41F
→
03/01 00:32, , 42F
03/01 00:32, 42F
→
03/01 00:33, , 43F
03/01 00:33, 43F
→
03/01 00:33, , 44F
03/01 00:33, 44F
→
03/01 00:35, , 45F
03/01 00:35, 45F
推
03/01 00:36, , 46F
03/01 00:36, 46F
→
03/01 00:38, , 47F
03/01 00:38, 47F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章