| 95 | | * 剩下 portfolio.js 跟 _amq.js 是比較重要的兩個 script. |
| | 95 | * 剩下 portfolio.js 跟 _amq.js 是比較重要的兩個 script. 首先來看 portfolio.js |
| | 96 | {{{ |
| | 97 | #!java |
| | 98 | // 註冊 PollHandler |
| | 99 | // 參考: _amq.js - addPollHandler : function(func) |
| | 100 | // * func: 函數指標(Function Pointer) |
| | 101 | amq.addPollHandler(portfolioPoll); |
| | 102 | |
| | 103 | // 這裡的 first 定義在 _amq.js 裡,預設值 _first: true |
| | 104 | function portfolioPoll(first) |
| | 105 | { |
| | 106 | if (first) |
| | 107 | { |
| | 108 | // 參考: _amq.js - addListener : function(id,destination,handler) |
| | 109 | // * id: Handler id |
| | 110 | // * destination: Listen to a Message Channel or Topic |
| | 111 | // * handler: 函數指標, 發生事件時的 callback 函數, 必須能處理 message 函數 |
| | 112 | amq.addListener('stocks','topic://STOCKS.*',priceHandler._price); |
| | 113 | } |
| | 114 | } |
| | 115 | |
| | 116 | // priceHandler 類別的 _price 函數宣告 |
| | 117 | var priceHandler = |
| | 118 | { |
| | 119 | _price: function(message) |
| | 120 | // 剩下的部份就是在處理 message 中的資料,忽略不看 |
| | 121 | } |
| | 122 | }}} |