Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16063

Re: referencing variable name for object in an array, receiving TypeError when using to set property of object

From JJ <jaejunks_at@_googlemail_dot._com>
Newsgroups comp.lang.javascript
Subject Re: referencing variable name for object in an array, receiving TypeError when using to set property of object
Date 2012-09-20 22:56 +0000
Organization A noiseless patient Spider
Message-ID <XnsA0D53CE8D69C8jaejunksgooglemailco@0.0.0.89> (permalink)
References <5f8cd44c-a554-42b4-bde5-5e099bdce516@googlegroups.com>

Show all headers | View raw


Quaye Trimble <qtrimble@gmail.com> wrote:

> This would probably be better described if I give you the link so you
> can follow along. 
> 
> https://bccmws.coastal.edu/buoydata/buoyobs1.html
> 
> The function initChart contains a single argument which defines the
> time period of data to display .  The function gets the data and
> configures some of the chart options.  Most of the chart options are
> already defined in a separate js file.  OK, so within this function,
> I'm referencing a global object called dataArr which stores some
> configuration information for querying the data and defining some
> additional chart options.  You can see how I'm constructing the object
> on line 185 if you are using Firebug or something similar.  If data is
> returned I'm calling the function setChart and passing a bunch of
> arguments into it.  The first argument contains the variable name of
> one of the external chart options object.  Using the Firebug console,
> the output is correct but I'm getting a TypeError.  It's as if the
> variable output isn't being used to define the chart option variable
> name but it's like it wants the variable name to be a completely
> different object. 
> 
> I'm not trained in JavaScript (or any programming language for that
> matter) so I'm probably doing something that isn't allowed. 
> 
> Let me know if I need to clarify anything and thanks for your
> willingness to help me. 
> 
> Quaye

The "setChart" function expects its "theChartOptions" parameter to be an 
object. However, in "initChar" function where it calls "setChart", it 
passes a string as the "theChartOptions" parameter:

setChart(dataArr[i].chartoptions,theDataObj,dataArr
[i].cname,type,chartNo);


Since "setChart" expects it to be one of the "optionsNN" object in the 
global context, then the call to "setChart" can be fixed like this:

setChart(window[dataArr[i].chartoptions],theDataObj,dataArr
[i].cname,type,chartNo);

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

referencing variable name for object in an array, receiving TypeError when using to set property of object Quaye Trimble <qtrimble@gmail.com> - 2012-09-20 10:51 -0700
  Re: referencing variable name for object in an array, receiving TypeError when using to set property of object JJ <jaejunks_at@_googlemail_dot._com> - 2012-09-20 22:56 +0000
    Re: referencing variable name for object in an array, receiving TypeError when using to set property of object Quaye Trimble <qtrimble@gmail.com> - 2012-10-10 05:28 -0700

csiph-web