我想知道下面的代码,我怎么能设置回调属性" value"为空?
代码带有一堆id(31,32,33),然后使用回调函数来监视这些id值的变化。当我使用相同的ID再次运行代码时,有没有办法将回调属性设置为null?
obsids = new Array();
function list() {
if (arguments.length) {
leng = arguments.length;
for (i = 0; i < leng; i++) {
obsids[i] = new LiveAPI(callback, "id "+arguments[i]);
obsids[i].property = "value";
}
}
function callback(args) {
outlet(0, args[0] + " " + args[1] + " " + this.id);
}
}
答案 0 :(得分:0)
您需要针对每个obsids[i]
进行特定回调,并且您需要create them in a closure才能放弃i
。
function list() {
var obsids = [];
for (var i=0, len = arguments.length; i < len; i++)
obsids[i] = createApi("id "+arguments[i]);
function createApi(id) {
var obsid = new LiveAPI(function callback(args) {
obsid.property = null;
outlet(0, args[0] + " " + args[1] + " " + this.id);
}, id);
obsid.property = "value";
return obsid;
}
return obsids;
}