Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #19049 > unrolled thread
| Started by | patrickmartin145@gmail.com |
|---|---|
| First post | 2013-03-29 15:06 -0700 |
| Last post | 2013-03-31 18:26 +0200 |
| Articles | 6 — 2 participants |
Back to article view | Back to comp.lang.javascript
Scoping issue I think patrickmartin145@gmail.com - 2013-03-29 15:06 -0700
Re: Scoping issue I think patrickmartin145@gmail.com - 2013-03-29 15:11 -0700
Re: Scoping issue I think patrickmartin145@gmail.com - 2013-03-29 15:29 -0700
Re: Scoping issue I think Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-29 23:43 +0100
Re: Scoping issue I think patrickmartin145@gmail.com - 2013-03-31 09:13 -0700
Re: Scoping issue I think Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-31 18:26 +0200
| From | patrickmartin145@gmail.com |
|---|---|
| Date | 2013-03-29 15:06 -0700 |
| Subject | Scoping issue I think |
| Message-ID | <f52678fa-29a5-4b1c-b125-9d3e5ec2eddb@googlegroups.com> |
I am really stuck here. The following code fails to set the children correctly. However I can see the correct values in _children with children being null.
I am pretty sure this is a scoping/privacy issue but I can't see anything wrong with my code.
/**
* Transforms:
* csv =
* {
* header : {C1,C2,C3},
* data : [
* [A,B,C],
* [A,B,D]
* ]
* }
* into:
* json =
* {
* "name" : rootName,
* "category" : category,
* "children" :
* [
* "children" :
* [
* {
* "name" : "A",
* "category" : "C1",
* "children" :
* [
* {
* "name" : "B",
* "category" : "C2",
* "children" :
* [
* {
* "name" : "C",
* "category" : "C3",
* "size" : 1
* }
* {
* "name" : "D",
* "category" : "C3",
* "size" : 1
* }
* ]
* }
* ]
* }
* ]
* ]
* }
*
* @param {Object} csv
*/
dex.csv.toHierarchicalJson = function(csv, rootName, rootCategory)
{
var connections = dex.csv.connections(csv);
var json =
{
"name" : rootName,
"category" : rootCategory,
"children" : dex.csv.getChildren(connections, 0)
}
getChildren(connections, depth)
{
//dex.console.log("connections:", connections, "depth="+depth);
var kids = [];
if ( typeof connections == 'undefined')
{
return kids;
}
for (var cname in connections)
{
//dex.console.log("CNAME", cname);
kids.push(
{
"name" : cname,
"category" : csv.header[depth],
"children" : dex.csv.getChildren(connections[cname], depth + 1)
});
}
return kids;
}
return json;
};
Any help would be greatly appreciated!!!
Thanks,
- Pat
[toc] | [next] | [standalone]
| From | patrickmartin145@gmail.com |
|---|---|
| Date | 2013-03-29 15:11 -0700 |
| Message-ID | <105662de-d6c1-4bdf-be85-8e7570596f93@googlegroups.com> |
| In reply to | #19049 |
On Friday, March 29, 2013 6:06:56 PM UTC-4, patrickm...@gmail.com wrote:
> I am really stuck here. The following code fails to set the children correctly. However I can see the correct values in _children with children being null.
>
>
>
> I am pretty sure this is a scoping/privacy issue but I can't see anything wrong with my code.
>
>
>
> /**
>
> * Transforms:
>
> * csv =
>
> * {
>
> * header : {C1,C2,C3},
>
> * data : [
>
> * [A,B,C],
>
> * [A,B,D]
>
> * ]
>
> * }
>
> * into:
>
> * json =
>
> * {
>
> * "name" : rootName,
>
> * "category" : category,
>
> * "children" :
>
> * [
>
> * "children" :
>
> * [
>
> * {
>
> * "name" : "A",
>
> * "category" : "C1",
>
> * "children" :
>
> * [
>
> * {
>
> * "name" : "B",
>
> * "category" : "C2",
>
> * "children" :
>
> * [
>
> * {
>
> * "name" : "C",
>
> * "category" : "C3",
>
> * "size" : 1
>
> * }
>
> * {
>
> * "name" : "D",
>
> * "category" : "C3",
>
> * "size" : 1
>
> * }
>
> * ]
>
> * }
>
> * ]
>
> * }
>
> * ]
>
> * ]
>
> * }
>
> *
>
> * @param {Object} csv
>
> */
>
> dex.csv.toHierarchicalJson = function(csv, rootName, rootCategory)
>
> {
>
> var connections = dex.csv.connections(csv);
>
> var json =
>
> {
>
> "name" : rootName,
>
> "category" : rootCategory,
>
> "children" : dex.csv.getChildren(connections, 0)
>
> }
>
>
>
> getChildren(connections, depth)
>
> {
>
> //dex.console.log("connections:", connections, "depth="+depth);
>
> var kids = [];
>
>
>
> if ( typeof connections == 'undefined')
>
> {
>
> return kids;
>
> }
>
>
>
> for (var cname in connections)
>
> {
>
> //dex.console.log("CNAME", cname);
>
> kids.push(
>
> {
>
> "name" : cname,
>
> "category" : csv.header[depth],
>
> "children" : dex.csv.getChildren(connections[cname], depth + 1)
>
> });
>
> }
>
> return kids;
>
> }
>
>
>
> return json;
>
> };
>
>
>
> Any help would be greatly appreciated!!!
>
>
>
> Thanks,
>
>
>
> - Pat
Information I might should have provided, if a csv were supplied of the form:
var csv = { header : [C1,C2,C3], [[A,B,C],[A,B,D]];
Then the connections object would look like:
connections = {A : { B : { C : {}, D : {} } } };
It's just a column-wise mapping of relationships contained within the CSV.
Thanks,
Pat
[toc] | [prev] | [next] | [standalone]
| From | patrickmartin145@gmail.com |
|---|---|
| Date | 2013-03-29 15:29 -0700 |
| Message-ID | <25ee3255-5e0d-49a7-a4d7-50707fa1c187@googlegroups.com> |
| In reply to | #19049 |
On Friday, March 29, 2013 6:06:56 PM UTC-4, patrickm...@gmail.com wrote:
> I am really stuck here. The following code fails to set the children correctly. However I can see the correct values in _children with children being null.
>
>
>
> I am pretty sure this is a scoping/privacy issue but I can't see anything wrong with my code.
>
>
>
> /**
>
> * Transforms:
>
> * csv =
>
> * {
>
> * header : {C1,C2,C3},
>
> * data : [
>
> * [A,B,C],
>
> * [A,B,D]
>
> * ]
>
> * }
>
> * into:
>
> * json =
>
> * {
>
> * "name" : rootName,
>
> * "category" : category,
>
> * "children" :
>
> * [
>
> * "children" :
>
> * [
>
> * {
>
> * "name" : "A",
>
> * "category" : "C1",
>
> * "children" :
>
> * [
>
> * {
>
> * "name" : "B",
>
> * "category" : "C2",
>
> * "children" :
>
> * [
>
> * {
>
> * "name" : "C",
>
> * "category" : "C3",
>
> * "size" : 1
>
> * }
>
> * {
>
> * "name" : "D",
>
> * "category" : "C3",
>
> * "size" : 1
>
> * }
>
> * ]
>
> * }
>
> * ]
>
> * }
>
> * ]
>
> * ]
>
> * }
>
> *
>
> * @param {Object} csv
>
> */
>
> dex.csv.toHierarchicalJson = function(csv, rootName, rootCategory)
>
> {
>
> var connections = dex.csv.connections(csv);
>
> var json =
>
> {
>
> "name" : rootName,
>
> "category" : rootCategory,
>
> "children" : dex.csv.getChildren(connections, 0)
>
> }
>
>
>
> getChildren(connections, depth)
>
> {
>
> //dex.console.log("connections:", connections, "depth="+depth);
>
> var kids = [];
>
>
>
> if ( typeof connections == 'undefined')
>
> {
>
> return kids;
>
> }
>
>
>
> for (var cname in connections)
>
> {
>
> //dex.console.log("CNAME", cname);
>
> kids.push(
>
> {
>
> "name" : cname,
>
> "category" : csv.header[depth],
>
> "children" : dex.csv.getChildren(connections[cname], depth + 1)
>
> });
>
> }
>
> return kids;
>
> }
>
>
>
> return json;
>
> };
>
>
>
> Any help would be greatly appreciated!!!
>
>
>
> Thanks,
>
>
>
> - Pat
Another correction. I've torn this code down and rebuilt it so many times, the post had a couple of issues.
/**
* Transforms:
* csv =
* {
* header : {C1,C2,C3},
* data : [
* [A,B,C],
* [A,B,D]
* ]
* }
* into:
* json =
* {
* "name" : rootName,
* "category" : category,
* "children" :
* [
* "children" :
* [
* {
* "name" : "A",
* "category" : "C1",
* "children" :
* [
* {
* "name" : "B",
* "category" : "C2",
* "children" :
* [
* {
* "name" : "C",
* "category" : "C3",
* "size" : 1
* }
* {
* "name" : "D",
* "category" : "C3",
* "size" : 1
* }
* ]
* }
* ]
* }
* ]
* ]
* }
*
* @param {Object} csv
*/
dex.csv.toHierarchicalJson = function(csv, rootName, rootCategory)
{
var connections = dex.csv.connections(csv);
var json =
{
"name" : rootName,
"category" : rootCategory,
"children" : getChildren(connections, 0)
}
function getChildren(connections, depth)
{
//dex.console.log("connections:", connections, "depth="+depth);
var kids = [];
if ( typeof connections == 'undefined')
{
return kids;
}
for (var cname in connections)
{
//dex.console.log("CNAME", cname);
kids.push(
{
"name" : cname,
"category" : csv.header[depth],
"children" : getChildren(connections[cname], depth + 1)
});
}
return kids;
}
dex.console.log("JSON: ", json);
return json;
};
Also, JSON logs like this, children being null and _children properly populated.
JSON: dex.js:103
Object
category: "ROOT"
children: Array[1]
0: Object
_children: Array[1]
0: Object
_children: Array[2]
0: Object
_children: Array[0]
category: "C3"
children: null
name: "C"
__proto__: Object
1: Object
_children: Array[0]
category: "C3"
children: null
name: "D"
__proto__: Object
length: 2
__proto__: Array[0]
category: "C2"
children: null
name: "B"
__proto__: Object
length: 1
__proto__: Array[0]
category: "C1"
children: null
name: "A"
__proto__: Object
length: 1
__proto__: Array[0]
name: "ROOT"
x0: 380
y0: 0
__proto__: Object
Apologies...
- Pat
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-03-29 23:43 +0100 |
| Message-ID | <1812795.mZEXYNaEgZ@PointedEars.de> |
| In reply to | #19049 |
patrickmartin145@gmail.com wrote:
^^^^^^^^^^^^^^^^^^^^^^^^^^
Who?
> I am really stuck here. The following code fails to set the children
> correctly. However I can see the correct values in _children with
> children being null.
>
> I am pretty sure this is a scoping/privacy issue
It has nothing to do with that.
> but I can't see anything wrong with my code.
Your code is syntactically valid, but it does not make sense (semantics
error).
> dex.csv.toHierarchicalJson = function(csv, rootName, rootCategory)
> {
> var connections = dex.csv.connections(csv);
> var json =
> {
> "name" : rootName,
> "category" : rootCategory,
> "children" : dex.csv.getChildren(connections, 0)
> }
>
> getChildren(connections, depth)
^^^^^^^^^^^
“ReferenceError: getChildren is not defined”
> {
^
In this context this is the delimiter of a Block statement, essentially a
no-op. ECMAScript implementations do not support implicit block scoping;
the scope of an identifier is defined by the execution context in which it
was defined. There are three types of execution contexts: global, function,
and eval (whereas the “with” statement is a special case).
> […]
> }
>
> return json;
> };
>
> Any help would be greatly appreciated!!!
Use the script console and RTFFAQ, RTFM next time, and get a working
keyboard.
--
PointedEars
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | patrickmartin145@gmail.com |
|---|---|
| Date | 2013-03-31 09:13 -0700 |
| Message-ID | <d6f9c4ba-f3ef-4baa-a56c-65e9a64b6598@googlegroups.com> |
| In reply to | #19049 |
On Friday, March 29, 2013 6:06:56 PM UTC-4, patrickm...@gmail.com wrote:
> I am really stuck here. The following code fails to set the children correctly. However I can see the correct values in _children with children being null.
>
>
>
> I am pretty sure this is a scoping/privacy issue but I can't see anything wrong with my code.
>
>
>
> /**
>
> * Transforms:
>
> * csv =
>
> * {
>
> * header : {C1,C2,C3},
>
> * data : [
>
> * [A,B,C],
>
> * [A,B,D]
>
> * ]
>
> * }
>
> * into:
>
> * json =
>
> * {
>
> * "name" : rootName,
>
> * "category" : category,
>
> * "children" :
>
> * [
>
> * "children" :
>
> * [
>
> * {
>
> * "name" : "A",
>
> * "category" : "C1",
>
> * "children" :
>
> * [
>
> * {
>
> * "name" : "B",
>
> * "category" : "C2",
>
> * "children" :
>
> * [
>
> * {
>
> * "name" : "C",
>
> * "category" : "C3",
>
> * "size" : 1
>
> * }
>
> * {
>
> * "name" : "D",
>
> * "category" : "C3",
>
> * "size" : 1
>
> * }
>
> * ]
>
> * }
>
> * ]
>
> * }
>
> * ]
>
> * ]
>
> * }
>
> *
>
> * @param {Object} csv
>
> */
>
> dex.csv.toHierarchicalJson = function(csv, rootName, rootCategory)
>
> {
>
> var connections = dex.csv.connections(csv);
>
> var json =
>
> {
>
> "name" : rootName,
>
> "category" : rootCategory,
>
> "children" : dex.csv.getChildren(connections, 0)
>
> }
>
>
>
> getChildren(connections, depth)
>
> {
>
> //dex.console.log("connections:", connections, "depth="+depth);
>
> var kids = [];
>
>
>
> if ( typeof connections == 'undefined')
>
> {
>
> return kids;
>
> }
>
>
>
> for (var cname in connections)
>
> {
>
> //dex.console.log("CNAME", cname);
>
> kids.push(
>
> {
>
> "name" : cname,
>
> "category" : csv.header[depth],
>
> "children" : dex.csv.getChildren(connections[cname], depth + 1)
>
> });
>
> }
>
> return kids;
>
> }
>
>
>
> return json;
>
> };
>
>
>
> Any help would be greatly appreciated!!!
>
>
>
> Thanks,
>
>
>
> - Pat
It turns out, the code was working just fine. There was another routine which was altering the data in the background before it got back to the console.
Thanks,
- Pat
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-03-31 18:26 +0200 |
| Message-ID | <2182953.ZuCaxiteiE@PointedEars.de> |
| In reply to | #19071 |
patrickmartin145@gmail.com wrote:
> [100+ lines of quote]
You can't be serious.
<http://jibbering.com/faq/#posting>
<http://PointedEars.de/faq#posting>
[Googlodyte-introduced, pointless intermediate empty lines removed]
>> […]
>> getChildren(connections, depth)
>> {
>> //dex.console.log("connections:", connections, "depth="+depth);
>>
>> var kids = [];
>>
>> if ( typeof connections == 'undefined')
>> {
>> return kids;
>> }
>>
>> for (var cname in connections)
>> {
>> //dex.console.log("CNAME", cname);
>>
>> kids.push(
>> {
>> "name" : cname,
>> "category" : csv.header[depth],
>> "children" : dex.csv.getChildren(connections[cname], depth + 1)
>> });
>> }
>>
>> return kids;
>> }
>>
>> return json;
>> };
>>
>> […]
>
> It turns out, the code was working just fine.
Doubtful. Have you read my other answer? If yes, have you understood it?
> There was another routine which was altering the data in the background
> before it got back to the console.
I would like to know the ECMAScript implementation with which this code
“works just fine”; that is, where the Function object referred to by
“getChildren” is _not_ [[Call]]ed when execution reaches the line
“getChildren(connections, depth)” followed by “{…}”.
--
PointedEars
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web