[英]How to extract selected Object properties to the newly created property with Array type?
[英]Where does this newly created object in the array gets its properties from?
我正在使用jQuery float,偶然发现一个我无法弄清楚的功能(控制台日志是我的):
function getOrCreateAxis(axes, number) {
console.log(" ");
console.log("getOrCreateAxis starting vars:");
console.log("Axes:");
console.log(axes);
console.log("Axes -1:");
console.log(axes[number-1]);
console.log("Xaxes:");
console.log(xaxes);
console.log("options are:");
console.log(options);
if (!axes[number - 1])
axes[number - 1] = {
n: number, // save the number for future reference
direction: axes == xaxes ? "x" : "y",
options: $.extend(true, {}, axes == xaxes ? options.xaxis : options.yaxis)
};
console.log("We're done in getOrCreateAxis, axes are:" + (axes == xaxes ? "x" : "y"));
console.log(axes);
console.log(" ");
return axes[number - 1];
}
据我了解,它接收到一个空数组,检查是否存在某些索引,如果不存在,它将在该索引处创建具有属性“ n”,“ direction”和“ options”(从另一个数组合并)的新对象。
我无法弄清楚的是,当您console.log axes数组时,除了上述三个以外的所有其他属性都来自哪里:
据我了解,有某种构造函数会自动使用其他属性填充对象,但我无法弄清楚它的来源或触发方式。 完整的Jquery Flot代码在这里可用,我正在努力使用的功能在980行上。
这个问题可能有点抽象,但是我在这里感到迷茫,因为从技术上我什至都不知道我在寻找什么。 什么在创建其他属性,我在哪里可以了解更多信息?
刻度不会添加到您粘贴的函数中( getOrCreateAxis()
)-它也发生在初始化阶段,但稍后会出现在setupGrid()
函数中:
// initialize
initPlugins(plot);
parseOptions(options_);
setupCanvases();
setData(data_);
setupGrid();
draw();
bindEvents();
如果跟踪setupGrid()
您会注意到它调用了您要查找的函数 setTicks()
,该函数在第1823行中进行了声明:
function setTicks(axis) {
var oticks = axis.options.ticks, ticks = [];
if (oticks == null || (typeof oticks == "number" && oticks > 0))
ticks = axis.tickGenerator(axis);
else if (oticks) {
if ($.isFunction(oticks))
// generate the ticks
ticks = oticks(axis);
else
ticks = oticks;
}
// clean up/labelify the supplied ticks, copy them over
var i, v;
axis.ticks = [];
for (i = 0; i < ticks.length; ++i) {
var label = null;
var t = ticks[i];
if (typeof t == "object") {
v = +t[0];
if (t.length > 1)
label = t[1];
}
else
v = +t;
if (label == null)
label = axis.tickFormatter(v, axis);
if (!isNaN(v))
axis.ticks.push({ v: v, label: label });
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.