本文介绍了未捕获的TypeError:..不是javascript中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用d3.js绘制折线图.

I am trying to use d3.js to draw line chart.

function lineChart(){
    ...
}

function update(){
    ...
    var lineChart = lineChart()
        .x(d3.scale.linear().domain([2011, 2014]))
        .y(d3.scale.linear().domain([0, 1000000]));
    ...
}

但是控制台显示Uncaught TypeError: lineChart is not a function.
该如何解决?

But the console says that Uncaught TypeError: lineChart is not a function.
How to fix this?

推荐答案

您正在屏蔽函数.

当您声明另一个变量/函数与上一个变量的名称相同时,会发生这种情况.您应该做的就是给第二个声明起另一个名字,就像@andlrc在他的评论中说的那样.

This happens when you declare another variable/function with the same name of an upper one. What you should do is to give another name to the second one declaration just like @andlrc says in his comment.

var lineChartResult = lineChart()...

您可以在此处了解有关阴影的更多信息:设置&阴影属性

You can learn more about shadowing in here: Setting & Shadowing Properties

这篇关于未捕获的TypeError:..不是javascript中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 04:42