一些小笔记。
“g{}” 是什么?
想看c 是什么呢?
为什么console 打出来上面要标出个 g 呢???
后来在stackOverflow上有人热心回答了我的问题:
This is typically an instance of an object defined with the following pattern, sometimes referred as the Constructor pattern:
// Car constructor function Car (miles) { this.miles = miles; } // Instantiate the object without arguments var car = new Car();
After minification of javascript, the
Car
function could be renamed to a variable likeg
. Thus, the debugger will show the valueg {}
for the instance of the car."What type it is ?"
It should now be obvious that it depends of the script. In your case it seems to be a
VehicleActionChannel
.
此提问帖后来被另一位读者给予了回答者和提问者(我)双重vote, 嘿嘿!很久赚不到分了。
getFields: function(text) { try { var fields = []; var matched = text.match(/{{[A-Za-z0-9_()]+}}/g); if (Array.isArray(matched)) { for (var idx = 0; idx < matched.length; idx++) { fields.push({ 'origin': matched[idx], 'name': matched[idx].replace(/{{|}}/g, '') }); } } return fields; } catch (e) { iAuto.Logger.error(e.stack); } },
解析一段数据,用正则过滤一个数组的有效数据。
getCurrentTime: function() { try { var date = new Date(); var dateStr = ''; dateStr = dateStr + (date.getMonth() + 1); dateStr = dateStr + '/' + date.getDate(); dateStr = dateStr + '/' + date.getFullYear(); var hours = date.getHours(); var minutes = date.getMinutes(); var seconds = date.getSeconds(); if (hours > 12) { dateStr = dateStr + ' ' + (hours - 12); } else { dateStr = dateStr + ' ' + hours; } minutes = minutes >= 10 ? minutes : '0' + minutes; seconds = seconds >= 10 ? seconds : '0' + seconds; dateStr = dateStr + ':' + minutes; dateStr = dateStr + ':' + seconds; if (hours >= 12) { dateStr = dateStr + ' PM'; } else { dateStr = dateStr + ' AM'; } return dateStr; } catch (e) { iAuto.Logger.error(e.stack); } },
解析时间的算法。
function Map(){ this.keys = new Array(); this.data = new Object(); var toString = Object.prototype.toString; /** * 当前Map当前长度 */ this.size = function(){ return this.keys.length; } /** * 添加值 * @param {Object} key * @param {Object} value */ this.put = function(key, value){ if(this.data[key] == null){ this.data[key] = value; } this.keys.push(key); } /** * 根据当前key获取value * @param {Object} key */ this.get = function(key){ return this.data[key]; } /** * 根据当前key移除Map对应值 * @param {Object} key */ this.remove = function(key){ var index = this.indexOf(key); if(index != -1){ this.keys.splice(index, 1); } this.data[key] = null; } /** * 清空Map */ this.clear = function(){ for(var i=0, len = this.size(); i < len; i++){ var key = this.keys[i]; this.data[key] = null; } this.keys.length = 0; } /** * 当前key是否存在 * @param {Object} key */ this.containsKey = function(key){ return this.data[key] != null; } /** * 是否为空 */ this.isEmpty = function(){ return this.keys.length === 0; } /** * 类型Java中Map.entrySet */ this.entrySet = function(){ var size = this.size(); var datas = new Array(size); for (var i = 0, len = size; i < len; i++) { var key = this.keys[i]; var value = this.data[key]; datas[i] = { 'key' : key, 'value':value } } return datas; } /** * 遍历当前Map * var map = new Map(); * map.put('key', 'value'); * map.each(function(index, key, value){ * console.log("index:" + index + "--key:" + key + "--value:" + value) * }) * @param {Object} fn */ this.each = function(fn){ if(toString.call(fn) === '[object Function]'){ for (var i = 0, len = this.size(); i < len; i++) { var key = this.keys[i]; fn(i, key, this.data[key]); } } return null; } /** * 获取Map中 当前key 索引值 * @param {Object} key */ this.indexOf = function(key){ var size = this.size(); if(size > 0){ for(var i=0, len=size; i < len; i++){ if(this.keys[i] == key) return i; } } return -1; } /** * Override toString */ this.toString = function(){ var str = "{"; for (var i = 0, len = this.size(); i < len; i++, str+=",") { var key = this.keys[i]; var value = this.data[key]; str += key + "=" + value; } str = str.substring(0, str.length-1); str += "}"; return str; } /** * 获取Map中的所有value值(Array) */ this.values = function(){ var size = this.size(); var values = new Array(); for(var i = 0; i < size; i++){ var key = this.keys[i]; values.push(this.data[key]); } return values; } }
JavaScript中 利用 Array和Object实现Map
利用FireEvent捕捉:
在console中模拟FC接收到数据后作出反应,trigger事件
fc = itu.fcontrol.get('BTEventManager'); fc.trigger("weatherInfo",{"getId": "cab46f28-eaf4-cb6c-310b-4cb1678cdb41", "weather": {"sunrise": "8:00","sunset": "19:00","city":"New York ,CA","dailyForecast":[{},{}]}, "error": true});
模拟接收到FC发来的数据后,事件得到响应
itu.event.fireEvent('popmessage', { 'type': 'notice', 'id': 'MSG_WEATHER', 'content': "volume!!!!", 'timeout': 6, 'toNC': true,