473,372 Members | 965 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,372 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 1405
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...
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...

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.