我的代码有问题,因为在输入以下 forEach 时“this.items”变量变为未定义。如您所见,console.log 显示 this.items 如果在 forEach 中重新定义
为什么?
仅供参考,我正在使用 jQuery 1.8 和 Classy(jQuery 的类管理器)
extractParams : function(params){
if(params != ""){
this.items = {};
params = params.split("&");
console.log(this.items);
params.forEach( function(dts){
console.log(this.items); // = undefined
this.keyval = dts.split("=");
console.log(this.items);
switch(keyval[0]){
case "v" :
this.items["Version number"] = this.keyval[1];
params = params.filter(function(v) { return !(v === "v=" + this.keyval[1] );});
break;
case "t1" :
console.log(this.item);
this.items["Event Type"] = this.keyval[1];
params = params.filter(function(v) { return !(v === "t1=" + this.keyval[1] );});
break;
default :
case "" :
break;
}
switch(true){
case regItem.test(keyval[0]):
this.items["Product Id n°" + this.keyval[0].match(regexpParamNumber)[1]] = this.keyval[1];
params = params.filter(function(v) { return !(v === "i"+this.keyval[0].match(regexpParamNumber)+"=" + this.keyval[1] );});
break;
case regQuantity.test(keyval[0]):
this.items["Quantity n°" + keyval[0].match(regexpParamNumber)[1]] = keyval[1];
params = params.filter(function(v) { return !(v === "q"+keyval[0].match(regexpParamNumber)+"=" + keyval[1] );});
break;
default :
case "" :
break;
}
})
console.log(result);
result[0] = detectTrackerType(this.items);
show(result);
}
return this.items;
}