473,385 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

inner classes proble

Hi, I've the following problem:

If I have, for example,

BB =
{
CC =
{
makeDecision : function()
{
return "ko";
},

b : isOk ? "ok" : makeDecision()
}
}

now if I done
BB.CC.b where isOK == false;

than I have na error that makeDecision() is not defined

now is not possible to assign a variable value calling a function?

how can I make that?

Thanks


Jun 27 '08 #1
6 945
"josh" <xd********@gmail.com>
If I have, for example,

BB =
{
CC =
{
makeDecision : function()
{
return "ko";
},

b : isOk ? "ok" : makeDecision()
}
}

now if I done
BB.CC.b where isOK == false;

than I have na error that makeDecision() is not defined
I am learning myself, so bear with me.
This has to do with the scope chain. The scope chain is altered when you
enter/leave a function. But you do not enter a function. You have an object
BB with property CC which is an object with two properties: makeDecision and
b. But 'entering' an object does not change the scope chain. BB.CC.b =
makeDicision() will be looking for makeDecision in the global execution
context. But it is not a property of the global variable and thus not
defined.
A solution would be to call BB.CC.makeDecision()

Tom
Jun 27 '08 #2
josh <xd********@gmail.comwrites:
Hi, I've the following problem:

If I have, for example,

BB =
{
CC =
{
makeDecision : function()
{
return "ko";
},

b : isOk ? "ok" : makeDecision()
}
}

now if I done
BB.CC.b where isOK == false;

than I have na error that makeDecision() is not defined
Yes, because there isn't one. You just made BB.CC.makeDecision. Assuming
you meant BB = { C: { ... } } instead of BB = { C = { ... } }
now is not possible to assign a variable value calling a function?
Sure it is, but you cannot refer to a property of an object literal
within the object literal.

IOW: you can't do:

var o = {
f: 2;
g: o.f;
}

or anything similar.

In your case, assuming you actually want makeDecision to be a property
of BB.CC, you can do:
var BB = { CC : { makeDecision: function() { return "ko" } } };

BB.CC.b = isOk ? "ok" : makeDecision();
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #3
Joost Diepenmaat wrote:
In your case, assuming you actually want makeDecision to be a property
of BB.CC, you can do:
var BB = { CC : { makeDecision: function() { return "ko" } } };

BB.CC.b = isOk ? "ok" : makeDecision();
Probably you meant something along

with (BB) CC.b = isOk ? "ok" : CC.makeDecision();

because there would not be such a method in the scope chain.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Jun 27 '08 #4
Thomas 'PointedEars' Lahn <Po*********@web.dewrites:
Joost Diepenmaat wrote:
>In your case, assuming you actually want makeDecision to be a property
of BB.CC, you can do:
var BB = { CC : { makeDecision: function() { return "ko" } } };

BB.CC.b = isOk ? "ok" : makeDecision();

Probably you meant something along

with (BB) CC.b = isOk ? "ok" : CC.makeDecision();

because there would not be such a method in the scope chain.
Erm, yeah that's what I meant. Although I wouldn't use with() in this
case.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #5
Joost Diepenmaat wrote:
Thomas 'PointedEars' Lahn <Po*********@web.dewrites:
>Joost Diepenmaat wrote:
>>In your case, assuming you actually want makeDecision to be a property
of BB.CC, you can do:

var BB = { CC : { makeDecision: function() { return "ko" } } };

BB.CC.b = isOk ? "ok" : makeDecision();
Probably you meant something along

with (BB) CC.b = isOk ? "ok" : CC.makeDecision();

because there would not be such a method in the scope chain.

Erm, yeah that's what I meant. Although I wouldn't use with() in this
case.
What better case is there? You know which properties the object has (so
`isOk' could not be looked up there), and you use the reference twice in a
statement.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jun 27 '08 #6
Thomas 'PointedEars' Lahn <Po*********@web.dewrites:
Joost Diepenmaat wrote:
>Erm, yeah that's what I meant. Although I wouldn't use with() in this
case.

What better case is there? You know which properties the object has (so
`isOk' could not be looked up there), and you use the reference twice in a
statement.
It's mostly a matter of taste, but I'd probably use it only if I was
dealing with a few (or a lot) more properties. The only place I've used
with() at all recently was with some code that had generator functions
for each HTML element (and I didn't want to make all of them global).

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: devu | last post by:
Currently I'm working on a class that performs a batch process as per scheduling for all employees in a company. Being a batch process load is obviously a huge factor. The process first needs to...
10
by: Paul Morrow | last post by:
I'm hoping that someone can explain why I get the following exception. When I execute the code... ###################################### class Parent(object): class Foo(object): baz = 'hello...
9
by: MariusI | last post by:
Consider the following class layout public class Order { public ProductOrder AddProductOrder(/* variables required to create a product order */) { /* Check if the product order can be added...
6
by: Philip Potter | last post by:
I have a graph data structure. It goes something like this: class GraphNode { private: friend class Graph; // successor GraphNodes stored as indices of the Graph's array int value; int next1,...
9
by: Matthias Buelow | last post by:
Hi folks, I've got something like: class Outer { int f(); friend class Inner; class Inner { int g() {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.