2016-07-05 49 views
0

我与jquery浮动工作,并且在一个功能我不能弄清楚绊(控制台日志矿):这个新创建的对象在数组中从哪里获取它的属性?

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”,“方向”和“选项”(从另一个数组合并而来)的新对象。

我无法弄清楚什么是所有超过三个以上从何而来,当你CONSOLE.LOG轴阵列之外的附加属性:

enter image description here

据我了解,有某种类型的构造函数会自动踢出填充对象的额外属性,但我无法弄清楚它来自哪里或如何触发。完整的jquery fllot代码可用here,我正在努力的功能是在980线上。

这个问题可能有点抽象,但我觉得迷失在这里,因为我甚至不知道我在找什么,技术上。什么是创造额外的属性,我在哪里可以阅读更多关于它?

+0

你有没有试着用调试器插手? – bhspencer

+0

我想你正在寻找[line 1837](https://github.com/flot/flot/blob/master/jquery.flot.js#L1837) – Bergi

+0

@bhspencer是的,通过调试器逐步完成创建的对象没有其他功能叫。 – Araklaj

回答

0

蜱不是在你粘贴功能(getOrCreateAxis())加入 - 它在Initialization阶段也发生了,但后来,在setupGrid()功能:如果您跟踪setupGrid()你可以看到,

// initialize 
initPlugins(plot); 
parseOptions(options_); 
setupCanvases(); 
setData(data_); 
setupGrid(); 
draw(); 
bindEvents(); 

calls the function you're looking for - setTicks(),这是在line 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 }); 
    } 
} 
+0

我可能误解了事物的顺序,但收到的数据'setTicks(axis)'似乎已经设置了ticks属性:http://i.imgur.com/lAm0Iy1.png'getOrCreateAxis ()'通过parseOptions(options_)调用'setupGrid()'之前调用' 因此,在我的第一个问题看到控制台日志,getOrCreateAxis()接收空数组,包装对象,该对象具有外部属性。 – Araklaj

+0

问题是,当您在Developer Tools中展开记录的对象时,它会显示其当前属性(执行完整个代码后),而不是在console.log被触发时的属性。直接尝试'console.log(axes [0] .ticks)',而不是'console.log(axes [0])',它应该返回'undefined'。 –

+1

..基于此,由于我对chrome开发工具的误解,花了数小时。谢谢@van_folmert – Araklaj

相关问题