469,270 Members | 1,398 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

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 1346
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Ken in Melbourne Australia | last post: by
12 posts views Thread by Tim Daneliuk | last post: by
8 posts views Thread by Jan van Veldhuizen | last post: by
4 posts views Thread by D | last post: by
1 post views Thread by Materialised | last post: by
2 posts views Thread by Ed Jay | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.