473,398 Members | 2,088 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,398 software developers and data experts.

Syntax for variables within a namespace


var BN = {
foo: function() {
alert("hello world");
},
z: function() {
alert("hello world");
},
}

I would like to add a member moo to BN whose definition is

var moo = {"a":"A","b","B"};

How do I do it?

Thanks

Sep 11 '07 #1
9 1408
Lee
gi*******************@yahoo.com said:
>

var BN = {
foo: function() {
alert("hello world");
},
z: function() {
alert("hello world");
},
}

I would like to add a member moo to BN whose definition is

var moo = {"a":"A","b","B"};

How do I do it?
The right hand side of your assignment to moo isn't valid Javascript syntax, so
there is no way to add it to BN. What are you really trying to do?
--

Sep 11 '07 #2

moo is a hash.
var moo = {"a":"A","b":"B"};
Sep 11 '07 #3
On Sep 12, 6:27 am, "gimme_this_gimme_t...@yahoo.com"
<gimme_this_gimme_t...@yahoo.comwrote:
var BN = {
foo: function() {
alert("hello world");
},
z: function() {
alert("hello world");
},
Variable names starting with capital letters are usually reserved for
constructors. That last comma is a syntax error.

}

I would like to add a member moo to BN whose definition is

var moo = {"a":"A","b","B"};
Another stray comma, and property names don't need to be quoted in
object literals:

var moo = {a:"A", b:"B"};

How do I do it?
To add a property moo to the object BN:

BN.moo = {...};
--
Rob

Sep 11 '07 #4
Can you make the assignment withing the braces?

As in

BN = {
// create moo here
}
Sep 11 '07 #5
RobG wrote:
On Sep 12, 6:27 am, "gimme_this_gimme_t...@yahoo.com"
<gimme_this_gimme_t...@yahoo.comwrote:
>var BN = {
foo: function() {
alert("hello world");
},
z: function() {
alert("hello world");
},

Variable names starting with capital letters are usually reserved for
constructors.
ACK
That last comma is a syntax error.
Strictly adhering to the ECMA-262 Ed. 3 grammar, yes. Considering the
Conformance section of ECMA-262 (all editions so far), no.
[...] property names don't need to be quoted in object literals:
Not quite correct.
var moo = {a:"A", b:"B"};
It is only possible to omit the quote characters or apostrophes around
the property name here because `a' and `b' are identifiers.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Sep 11 '07 #6
Thanks.

Sep 11 '07 #7
gi*******************@yahoo.com wrote:
var BN = {
foo: function() {
alert("hello world");
},
z: function() {
alert("hello world");
},
}

I would like to add a member moo to BN whose definition is

var moo = {"a":"A","b","B"};
var BN = {
foo: function() {
alert("hello world");
},
z: function() {
alert("hello world");
},
moo: {"a": "A", "b": "B"}
}

or you could have augmented your original BN:

BN.moo = {"a": "A", "b": "B"};

http://javascript.crockford.com/
Sep 12 '07 #8
Thomas 'PointedEars' Lahn meinte:
>That last comma is a syntax error.

Strictly adhering to the ECMA-262 Ed. 3 grammar, yes. Considering the
Conformance section of ECMA-262 (all editions so far), no.
One should note, that IE (6) has it's problems with this extra comma. FF
and Opera (and suppose others) not.

Gregor
--
http://www.gregorkofler.at ::: Landschafts- und Reisefotografie
http://www.licht-blick.at ::: Forum für Multivisionsvorträge
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Sep 12 '07 #9
On Tue, 11 Sep 2007 at 23:33:31, in comp.lang.javascript, Thomas
'PointedEars' Lahn wrote:
>RobG wrote:
<snip>
>That last comma is a syntax error.

Strictly adhering to the ECMA-262 Ed. 3 grammar, yes. Considering the
Conformance section of ECMA-262 (all editions so far), no.
<snip>

The Conformance section is there to permit extra features. It's not
there to permit random typing errors. A certain amount of common sense
is assumed, of browser designers as well as of web designers.

John
--
John Harris
Sep 15 '07 #10

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

Similar topics

8
by: Ken in Melbourne Australia | last post by:
If I use the curly bracket syntax (referred to as the complex syntax) within a string, how do I get to call a function within it? The php manual says that the first (or previous) character for...
12
by: Tim Daneliuk | last post by:
I am a bit confused. I was under the impression that: class foo(object): x = 0 y = 1 means that x and y are variables shared by all instances of a class. But when I run this against two...
8
by: Jan van Veldhuizen | last post by:
The UPDATE table FROM syntax is not supported by Oracle. I am looking for a syntax that is understood by both Oracle and SqlServer. Example: Table1: id name city ...
4
by: D | last post by:
( new to C++ ) How does one make an "object" global? I know from C that you can declare a variable outside of main and it's global. And all functions are proto'ed and defined outside of main (and...
8
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. ...
4
by: Stephen Corey | last post by:
I've got 2 classes in 2 seperate header files, but within the same namespace. If I use a line like: // This code is inside Class2's header file Class1 *newitem = new Class1(param1, param2); ...
1
by: Materialised | last post by:
Hi All, I am trying the follow the following MSDN tutorial: Walkthrough: Authoring a Simple Multithreaded Component with Visual C#...
2
by: Ed Jay | last post by:
I have two functions, one of which is called from within the other, which is called from an HTML page. The called function is passed parameters that I'd like to pass to the argument calling the...
10
by: Cliff | last post by:
Greetings, I have been trying to teach myself C++ over the past few weeks and have finally came across a problem I could not fix. I made a simple program that prints out a square or rectangle...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.