364,083 Members | 5803 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

How to list the statement of all var ?

Thierry Loiseau
P: n/a
Thierry Loiseau
Hello all,

and Happy end year 2005 !

Well, I would like to obtain a list of all JavaScript var statement,
With "for...in" perharps ?

That is bellow my recent test here, but the problem is to management
theses :-((( I must to declare and use all variable with this scheme :

v['name']

Thanx for all suggestion !

================================================== ======================
<html>
<head>
<title>for...in (var)</title>
</head>
<body>
<script type="text/javascript">
<!--
var v=new Array();
v['titi']="";
v['bleah']='toto';
v['toto']='bibi';
v['tutu']=109;
v['annonce_fr']="Bonne f&ecirc;tes de fin d'ann&eacute;e !";
v['annonce_en']="Happy new year, this is the end of the year 2005...
Hello 2006 !!";
function print_all() {
for (var i in window.v) {
v['titi']=(typeof(window.v[i])=="string")?" ' ":"";
document.write(i + " = " + v['titi'] +
"<span style='color: blue; font-weight:bold;'>"+window.v[i]+"</span>"
+
v['titi'] + "<br>\n");
}
}
print_all();
document.write("<hr> v['tutu']+2 = "+(v['tutu']+2));
// -->
</script>
</body>
</html>
================================================== ======================

Thierry
and best regards from France,

<http://www.google.com/maps?ll=45.128...5925,0.013087&
t=k&hl=fr>

PS : sorry for my bad english spoken :-(
Dec 26 '05 #1
Share this Question
Share on Google+
35 Replies


Martin Honnen
P: n/a
Martin Honnen


Thierry Loiseau wrote:

[color=blue]
> Well, I would like to obtain a list of all JavaScript var statement,
> With "for...in" perharps ?
>
> That is bellow my recent test here, but the problem is to management
> theses :-((( I must to declare and use all variable with this scheme :
>
> v['name'][/color]

The var statement declares a variable (or more) and might additionally
initialize variables e.g.
var varName;
or
var varName = 'Kibology';

v['name'] is a property access but obviously no var statement.

The language itself does not have a "Code object model" which would
allow your script code to access the code itself in a structured way
where you could look for statements or statements of a certain type.

But global variables declared with the var statement will become
properties of the global object (which is the window object in
client-side browser script) and properties of an object can be
enumerated using the for..in statement if those properties are not
marked with the internal attribute DontEnum. As the var statement
definition does not specify that that internal DontEnum attribute should
be set for declared variables being created as properties an
implementation should make all those declared variables enumerable with
for..in.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 26 '05 #2

Thierry Loiseau
P: n/a
Thierry Loiseau
Martin Honnen <mahotrash@yahoo.de> wrote:
[color=blue]
> The var statement declares a variable (or more) and might additionally
> initialize variables e.g.[/color]

I'm shure "statement" is no well come in my first message :-(((
In french, "Etat" ?

Thierry
Dec 26 '05 #3

Martin Honnen
P: n/a
Martin Honnen


Thierry Loiseau wrote:
[color=blue]
> Martin Honnen <mahotrash@yahoo.de> wrote:
>
>[color=green]
>>The var statement declares a variable (or more) and might additionally
>>initialize variables e.g.[/color]
>
>
> I'm shure "statement" is no well come in my first message :-(((
> In french, "Etat" ?[/color]

Sorry, I can't help, there is a French group fr.comp.lang.javascript as
far as I know where French is the main language, posting and reading
there might be more successful for you.
Google has it here:
<http://groups.google.com/group/fr.comp.lang.javascript?hl=en>
Hmm, I see you already post there, if that really does not help and you
want to post here then consider making a post with two languages,
English and French, here, that might then increase your chances that
someone here understands what you are looking for as you might have
someone read here who is fluent (enough) in French.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 26 '05 #4

VK
P: n/a
VK

Thierry Loiseau wrote:[color=blue]
> Martin Honnen <mahotrash@yahoo.de> wrote:
>[color=green]
> > The var statement declares a variable (or more) and might additionally
> > initialize variables e.g.[/color]
>
> I'm shure "statement" is no well come in my first message :-(((
> In french, "Etat" ?[/color]

"a state" - but this is a too vague term for the task description.
Based on the posted code you're trying to find either "valeur" (a
value) or "typage" (a type) - or both - of the v[i] elements. Could you
clarify please?
( Any recognizable version of the Shakespeare language goes just fine
;-)

Dec 26 '05 #5

Thierry Loiseau
P: n/a
Thierry Loiseau
VK <schools_ring@yahoo.com> wrote:
[color=blue]
> Thierry Loiseau wrote:[color=green]
> > Martin Honnen <mahotrash@yahoo.de> wrote:
> >[color=darkred]
> > > The var statement declares a variable (or more) and might additionally
> > > initialize variables e.g.[/color]
> >
> > I'm shure "statement" is no well come in my first message :-(((
> > In french, "Etat" ?[/color]
>
> "a state" - but this is a too vague term for the task description.[/color]

Right ! Ok !
[color=blue]
> Based on the posted code you're trying to find either "valeur" (a
> value) or "typage" (a type) - or both - of the v[i] elements. Could you
> clarify please?
> ( Any recognizable version of the Shakespeare language goes just fine
> ;-)[/color]

Ok. Thank you for your post. Than my example, I would like to get value
of each !

With my script =

================================================== ======================
<html>
<head>
<title>for...in (var)</title>
</head>
<body>
<script type="text/javascript">
<!--
var v=new Array();
v['titi']="";
v['bleah']='toto';
v['toto']='bibi';
v['tutu']=109;
v['annonce_fr']="Bonne nouvelle ann&eacute;e 2006 !!";
v['annonce_en']="Happy new year 2006 !!";
function print_all() {
for (var i in window.v) {
v['titi']=(typeof(window.v[i])=="string")?" ' ":"";
document.write(i + " = " + v['titi'] +
"<span style='color: blue; font-weight:bold;'>"+window.v[i]+"</span>"
+
v['titi'] + "<br>\n");
}
}
print_all();
document.write("<hr> v['tutu']+2 = "+(v['tutu']+2));
// -->
</script>
</body>
</html>
================================================== ======================

The result is :

================================================== ======================

titi = ' ' '
bleah = ' toto '
toto = ' bibi '
tutu = 109
annonce_fr = ' Bonne nouvelle année 2006 !! '
annonce_en = ' Happy new year 2006 !! '
v['tutu']+2 = 111
================================================== ======================

I repeat : the problem is to management theses :-(((
So, I must to declare and use all variable with this strict scheme
(syntax, scheme is a good word ?) :

v['name']

Thanx for all suggestion !

Thierry,
best regards from France
Dec 26 '05 #6

Thierry Loiseau
P: n/a
Thierry Loiseau
VK <schools_ring@yahoo.com> wrote:
[color=blue]
> Thierry Loiseau wrote:[color=green]
> > Martin Honnen <mahotrash@yahoo.de> wrote:
> >[color=darkred]
> > > The var statement declares a variable (or more) and might additionally
> > > initialize variables e.g.[/color]
> >
> > I'm shure "statement" is no well come in my first message :-(((
> > In french, "Etat" ?[/color]
>
> "a state" - but this is a too vague term for the task description.[/color]

Right ! Ok !
[color=blue]
> Based on the posted code you're trying to find either "valeur" (a
> value) or "typage" (a type) - or both - of the v[i] elements. Could you
> clarify please?
> ( Any recognizable version of the Shakespeare language goes just fine
> ;-)[/color]

Ok. Thank you for your post. Than my example, I would like to get value
of each !

With my script =

================================================== ======================
<html>
<head>
<title>for...in (var)</title>
</head>
<body>
<script type="text/javascript">
<!--
var v=new Array();
v['titi']="";
v['bleah']='toto';
v['toto']='bibi';
v['tutu']=109;
v['annonce_fr']="Bonne nouvelle ann&eacute;e 2006 !!";
v['annonce_en']="Happy new year 2006 !!";
function print_all() {
for (var i in window.v) {
v['titi']=(typeof(window.v[i])=="string")?" ' ":"";
document.write(i + " = " + v['titi'] +
"<span style='color: blue; font-weight:bold;'>"+window.v[i]+"</span>"
+ v['titi'] + " [" + typeof(window.v[i]) + "]<br>\n");
}
}
print_all();
document.write("<hr> v['tutu']+2 = "+(v['tutu']+2));
// -->
</script>
</body>
</html>
================================================== ======================

The result is :

================================================== ======================

titi = ' ' '
bleah = ' toto '
toto = ' bibi '
tutu = 109
annonce_fr = ' Bonne nouvelle année 2006 !! '
annonce_en = ' Happy new year 2006 !! '
v['tutu']+2 = 111
================================================== ======================

I repeat : the problem is to management theses :-(((
So, I must to declare and use all variable with this strict scheme
(syntax, scheme is a good word ?) :

v['name']

Thanx for all suggestion !

Thierry,
best regards from France
Dec 26 '05 #7

Thierry Loiseau
P: n/a
Thierry Loiseau
VK <schools_ring@yahoo.com> wrote:
[color=blue]
> Thierry Loiseau wrote:[color=green]
> > Martin Honnen <mahotrash@yahoo.de> wrote:
> >[color=darkred]
> > > The var statement declares a variable (or more) and might additionally
> > > initialize variables e.g.[/color]
> >
> > I'm shure "statement" is no well come in my first message :-(((
> > In french, "Etat" ?[/color]
>
> "a state" - but this is a too vague term for the task description.[/color]

Right ! Ok !
[color=blue]
> Based on the posted code you're trying to find either "valeur" (a
> value) or "typage" (a type) - or both - of the v[i] elements. Could you
> clarify please?
> ( Any recognizable version of the Shakespeare language goes just fine
> ;-)[/color]

Ok. Thank you for your post. Than my example, I would like to get value
of each !

With my script =

================================================== ======================
<html>
<head>
<title>for...in (var)</title>
</head>
<body>
<script type="text/javascript">
<!--
var v=new Array();
v['titi']="";
v['bleah']='toto';
v['toto']='bibi';
v['tutu']=109;
v['annonce_fr']="Bonne nouvelle ann&eacute;e 2006 !!";
v['annonce_en']="Happy new year 2006 !!";
function print_all() {
for (var i in window.v) {
v['titi']=(typeof(window.v[i])=="string")?" ' ":"";
document.write(i + " = " + v['titi'] +
"<span style='color: blue; font-weight:bold;'>"+window.v[i]+"</span>"
+ v['titi'] + " [" + typeof(window.v[i]) + "]<br>\n");
}
}
print_all();
document.write("<hr> v['tutu']+2 = "+(v['tutu']+2));
// -->
</script>
</body>
</html>
================================================== ======================

The result print in the page is :

================================================== ======================
titi = ' ' ' [string]
bleah = ' toto ' [string]
toto = ' bibi ' [string]
tutu = 109 [number]
annonce_fr = ' Bonne nouvelle année 2006 !! ' [string]
annonce_en = ' Happy new year 2006 !! ' [string]
v['tutu']+2 = 111
================================================== ======================

I repeat : the problem is to management theses :-(((
So, I must to declare and use all variable with this strict scheme
(syntax, scheme is a good word ?) :

v['name']

Thanx for all suggestion !

Thierry,
best regards from France
Dec 26 '05 #8

VK
P: n/a
VK

Thierry Loiseau wrote:[color=blue]
> I repeat : the problem is to management theses :-(((
> So, I must to declare and use all variable with this strict scheme
> (syntax, scheme is a good word ?) :
>
> v['name']
>[/color]

Array ("rangee") consists of arrayObject.length elements and you handle
them by their index which is positive integer:
v[10] = 'foo';
alert(v[10]);

The posted structure is *not* an array. So proper way to handle it
would be (one of possibilities):

var v=new Object(); // not Array!
v['titi']="";
v['bleah']='toto';
v['toto']='bibi';
v['tutu']=109;
v['annonce_fr']="Bonne nouvelle ann&eacute;e 2006 !!";
v['annonce_en']="Happy new year 2006 !!";
etc. as you already do

And of course no one stops you from declaring separate variables which
are not parts of any higher structure:

var blah_blah_blah = "blah-blah-blah";

I guess you need to find a good French manual of JavaScript (I cannot
advise any).
For English reading you may visit:
<http://www.geocities.com/schools_ring/ArrayAndHash.html>



:-D ;-)

Dec 26 '05 #9

Thierry Loiseau
P: n/a
Thierry Loiseau
VK <schools_ring@yahoo.com> wrote:
[color=blue]
> Thierry Loiseau wrote:[color=green]
> > I repeat : the problem is to management theses :-(((
> > So, I must to declare and use all variable with this strict scheme
> > (syntax, scheme is a good word ?) :
> >
> > v['name']
> >[/color]
>
> Array ("rangee") consists of arrayObject.length elements and you handle
> them by their index which is positive integer:
> v[10] = 'foo';
> alert(v[10]);
>
> The posted structure is *not* an array. So proper way to handle it
> would be (one of possibilities):
>
> var v=new Object(); // not Array![/color]

Ok !
[color=blue]
> v['titi']="";
> v['bleah']='toto';
> v['toto']='bibi';
> v['tutu']=109;
> v['annonce_fr']="Bonne nouvelle ann&eacute;e 2006 !!";
> v['annonce_en']="Happy new year 2006 !!";
> etc. as you already do
>
> And of course no one stops you from declaring separate variables which
> are not parts of any higher structure:
>
> var blah_blah_blah = "blah-blah-blah";
>
> I guess you need to find a good French manual of JavaScript (I cannot
> advise any).
> For English reading you may visit:
> <http://www.geocities.com/schools_ring/ArrayAndHash.html>[/color]

Ok (too). So I make a long script to my (sorry in french) personal
homepage.

<http://astrophoto.free.fr/calculs/calculs.js>
[color=blue]
> :-D ;-)[/color]

Yep !

Thanx VK !

Thierry Loiseau
and Best regards
From France
Dec 26 '05 #10

Thierry Loiseau
P: n/a
Thierry Loiseau
VK <schools_ring@yahoo.com> wrote:
[color=blue]
> Thierry Loiseau wrote:[color=green]
> > I repeat : the problem is to management theses :-(((
> > So, I must to declare and use all variable with this strict scheme
> > (syntax, scheme is a good word ?) :
> >
> > v['name']
> >[/color]
>
> Array ("rangee") consists of arrayObject.length elements and you handle
> them by their index which is positive integer:
> v[10] = 'foo';
> alert(v[10]);
>
> The posted structure is *not* an array. So proper way to handle it
> would be (one of possibilities):
>
> var v=new Object(); // not Array![/color]

Ok ! But my script run with a good result, no ?
[color=blue]
> v['titi']="";
> v['bleah']='toto';
> v['toto']='bibi';
> v['tutu']=109;
> v['annonce_fr']="Bonne nouvelle ann&eacute;e 2006 !!";
> v['annonce_en']="Happy new year 2006 !!";
> etc. as you already do
>
> And of course no one stops you from declaring separate variables which
> are not parts of any higher structure:
>
> var blah_blah_blah = "blah-blah-blah";
>
> I guess you need to find a good French manual of JavaScript (I cannot
> advise any).
> For English reading you may visit:
> <http://www.geocities.com/schools_ring/ArrayAndHash.html>[/color]

Ok (too). So I make a long script to my (sorry in french) personal
homepage.

<http://astrophoto.free.fr/calculs/calculs.js>
[color=blue]
> :-D ;-)[/color]

Yep !

Thanx VK !

Thierry Loiseau
and Best regards
From France
Dec 26 '05 #11

VK
P: n/a
VK

Thierry Loiseau wrote:[color=blue]
> So I make a long script to my (sorry in french) personal
> homepage.
>
> <http://astrophoto.free.fr/calculs/calculs.js>[/color]

Cool! So does everything work as expected now?

[color=blue][color=green]
> > :-D ;-)[/color]
>
> Yep ![/color]

Smilies were not to you directly, just a... conditional signature :-)

Dec 26 '05 #12

Thierry Loiseau
P: n/a
Thierry Loiseau
VK <schools_ring@yahoo.com> wrote:
[color=blue][color=green]
> > So I make a long script to my (sorry in french) personal
> > homepage.
> >
> > <http://astrophoto.free.fr/calculs/calculs.js>[/color]
>
> Cool! So does everything work as expected now?[/color]

From <http://astrophoto.free.fr/calculs/>
=> clic on button "simulateur copernic" and after onload, clic on
"astrophoto"... :-)))
=> clic on button "Lunes de Jupiter" and clic on the item "Repères", on
left, top, twice to view animation...

=> clic on button "visibilité des planètes", clic on the image-planete
then, there is a popup, and you see the position of this in the sky.
=> clic on button "astrophoto" to see the constelllation...
[color=blue]
>[color=green][color=darkred]
> > > :-D ;-)[/color]
> >
> > Yep ![/color]
>
> Smilies were not to you directly, just a... conditional signature :-)[/color]

Argh, ok !-)

Best regards from France,

Thierry

PS : VK, do you speak french ?
Dec 26 '05 #13

Jasen Betts
P: n/a
Jasen Betts
On 2005-12-26, Thierry Loiseau <loiseauthierry@free.fr> wrote:[color=blue]
> Martin Honnen <mahotrash@yahoo.de> wrote:
>[color=green]
>> The var statement declares a variable (or more) and might additionally
>> initialize variables e.g.[/color]
>
> I'm shure "statement" is no well come in my first message :-(((
> In french, "Etat" ?[/color]

I know very little French, "Etat" is like the english word "nation" ???

"a statement" is like "a thing said"

"var statement" in this context is a piece of javascript
that that starts with "var"

example:

var a=10,b=20;


Bye.
Jasen
Dec 26 '05 #14

RobG
P: n/a
RobG
Thierry Loiseau wrote:[color=blue]
> VK <schools_ring@yahoo.com> wrote:[/color]
[...][color=blue][color=green]
>>
>>The posted structure is *not* an array. So proper way to handle it
>>would be (one of possibilities):
>>
>>var v=new Object(); // not Array![/color]
>
>
> Ok ! But my script run with a good result, no ?[/color]

Because Arrays are Objects, so you can do with them everything that
you can do with ordinary objects.

Arrays are a special objects with a property 'length' and a number of
special methods - splice, push, pop, concat et cetera - but otherwise
they are just like other objects.

VK suggested using an ordinary object because you weren't using the
special property or methods of an array.


[...]


--
Rob
Dec 26 '05 #15

VK
P: n/a
VK

Thierry Loiseau wrote:[color=blue]
> Ok ! But my script run with a good result, no ?[/color]

It does... until when... because any JavaScript/JScript objext extends
Object constructor.

By the usage twist it is similar to:

function f1() {
with (arguments.callee) {
return arg1 + arg2;
}
}

f1.arg1 = 2;
f1.arg2 = 2;
alert(f1());

Here too you're declaring *function* f1 but overloading it as a
primitive Object. JavaScript is flexible enough for such and even more
weird things, but not would it be better to use the conventional way?

function f1(arg1, arg2) {
return arg1+arg2;
}

alert(f1(2,2));

You need to use hacks only when you have too. Otherwise you should use
the things with the intended purposes and in the intended way.
IMHighlyHO

Dec 27 '05 #16

VK
P: n/a
VK
[color=blue]
> VK <schools_ring@yahoo.com> wrote:[color=green]
> > The posted structure is *not* an array. So proper way to handle it
> > would be (one of possibilities):
> >
> > var v=new Object(); // not Array![/color][/color]

Thierry Loiseau wrote:[color=blue]
> Ok ! But my script run with a good result, no ?[/color]

It does... until when... because any JavaScript/JScript objext extends
Object constructor.

So by the usage twist it is similar to:

function f1() {
with (arguments.callee) {
return arg1 + arg2;
}
}

f1.arg1 = 2;
f1.arg2 = 2;
alert(f1());

Here too you're declaring a "Function* object but using it as an Object
object. JavaScript is flexible enough for even more tricky things. But
wouldn't it be better to use the conventional way:

function f1(arg1, arg2) {
return arg1 + arg2;
}

alert(f1(2,2));

You should use hacks only if you have too otherwise you should use
things in the conventional way with the conventional purpose.
IMHighlyHO

Dec 27 '05 #17

Thomas 'PointedEars' Lahn
P: n/a
Thomas 'PointedEars' Lahn
VK wrote:
[color=blue]
> Thierry Loiseau wrote:[color=green]
>> Ok ! But my script run with a good result, no ?[/color]
>
> It does... until when... because any JavaScript/JScript objext extends
> Object constructor.[/color]

Wrong. What you maybe meant to say was that user-defined objects
inherit properties from the Object prototype which would be disabled
for an inheriting object as long as their name would be used as name
of a property of that object.
[color=blue]
> By the usage twist it is similar to:
>
> function f1() {
> with (arguments.callee) {
> return arg1 + arg2;
> }
> }
>
> f1.arg1 = 2;
> f1.arg2 = 2;
> alert(f1());
>
> Here too you're declaring *function* f1 but overloading it as a
> primitive Object.[/color]

Nothing is "overloaded" here. As in functional programming languages,
functions _are_ (first-class) objects in J(ava)Script/ECMAScript:
Function objects. Neither objects nor references are primitive values.


PointedEars
Dec 27 '05 #18

zwetan
P: n/a
zwetan
Hello,
[color=blue]
>
> Well, I would like to obtain a list of all JavaScript var statement,
> With "for...in" perharps ?
>
> That is bellow my recent test here, but the problem is to management
> theses :-((( I must to declare and use all variable with this scheme :
>
> v['name']
>
> Thanx for all suggestion ![/color]
[snip]

If you want to trace into an associative Array, use an object Object instead

in FF for ex:
---------------
var v=new Object();
v['titi']="";
v['bleah']='toto';
v['toto']='bibi';
v['tutu']=109;
v['annonce_fr']="Bonne f&ecirc;tes de fin d'ann&eacute;e !";
v['annonce_en']="Happy new year, this is the end of the year 2005...Hello
2006 !!";

document.write( "v:"+v.toSource() );
---------------

will trace
---------------
v:({titi:"", bleah:"toto", toto:"bibi", tutu:109, annonce_fr:"Bonne fêtes
de fin d'année !", annonce_en:"Happy new year, this is the end of the year
2005...Hello 2006 !!"})
---------------


if you want the same functionality in any browser you can also use my core2
library
http://www.burrrn.com/projects/core2.html

here an exemple
---------------
<html>
<body>
<head>
<script type="text/javascript" src="core2_v1.0.0_JS.js"></script>

<style type="text/css">

html
{
height: 100%;
overflow: hidden;
}

body
{
height: 100%;
margin: 0;
padding: 0;
background-color: #FFFFFF;
}

#TraceConsole
{
width: 600px;
/* height: 400%; */
text-align: left;
font-size: 12px;
/* font-family: monospace; */
/* font-family: tahoma, Verdana, Helvetica, Sans-Serif; */
font-family: courier,fixed,swiss,sans-serif;
border: 1px dotted #cccccc;
display: block;
}

</style>
</head>
<title>blah</title>
<html>
<div id="TraceConsole"></div>
<script type="text/javascript">

var v=new Object();
v['titi']="";
v['bleah']='toto';
v['toto']='bibi';
v['tutu']=109;
v['annonce_fr']="Bonne f&ecirc;tes de fin d'ann&eacute;e !";
v['annonce_en']="Happy new year, this is the end of the year 2005...Hello
2006 !!";

trace( "v:"+v.toSource( 0 ) );

</script>

</body>
</html>
---------------

will trace in the DIV
---------------
v:
{
titi:"",
bleah:"toto",
toto:"bibi",
tutu:109,
annonce_fr:"Bonne fêtes de fin d\'année !",
annonce_en:"Happy new year, this is the end of the year 2005...Hello
2006 !!"
}
---------------

Alternatively you could also use another way of organizing your local
strings

for exemple:
---------------
var AnnounceStrings = new Object();
AnnounceStrings.fr = new Object();
AnnounceStrings.en = new Object();

AnnounceStrings.fr.happyNewyear = "Bonne f&ecirc;tes de fin d'ann&eacute;e
!";
AnnounceStrings.fr.hello = "bonjour {0}";

AnnounceStrings.en.happyNewyear ="Happy new year, this is the end of the
year 2005...Hello 2006 !!";
AnnounceStrings.en.hello = "hello {0}";

trace( "AnnounceStrings:"+AnnounceStrings.toSource( 0 ) );

var userName = "toto";
var lang = "fr";

trace( "--------" );
trace( String.format( AnnounceStrings[ lang ].hello, userName ) );
---------------


will trace in the DIV
---------------
AnnounceStrings:
{
fr:
{
happyNewyear:"Bonne fêtes de fin d\'année !",
hello:"bonjour {0}"
},
en:
{
happyNewyear:"Happy new year, this is the end of the year
2005...Hello 2006 !!",
hello:"hello {0}"
}
}
--------
bonjour toto
---------------

HTH
zwetan


Dec 27 '05 #19

Thomas 'PointedEars' Lahn
P: n/a
Thomas 'PointedEars' Lahn
zwetan wrote:
[color=blue][color=green]
>> Well, I would like to obtain a list of all JavaScript var statement,
>> With "for...in" perharps ?[/color][/color]

Please provide attribution of quoted material:

<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
[color=blue][color=green]
>> That is bellow my recent test here, but the problem is to management
>> theses :-((( I must to declare and use all variable with this scheme :
>>
>> v['name']
>> [...][/color]
> [snip]
>
> If you want to trace into an associative Array, use an object Object
> instead[/color]

Probably you meant to say "There are no associative Arrays in JS/ECMAScript.
What is achieved with associative arrays in other languages, is provided by
properties of objects and property accessors here."
[color=blue]
> in FF for ex:
> ---------------
> var v=new Object();
> v['titi']="";
> v['bleah']='toto';
> v['toto']='bibi';
> v['tutu']=109;
> v['annonce_fr']="Bonne f&ecirc;tes de fin d'ann&eacute;e !";
> v['annonce_en']="Happy new year, this is the end of the year 2005...Hello
> 2006 !!";
>
> document.write( "v:"+v.toSource() );
> ---------------
>
> will trace
> ---------------
> v:({titi:"", bleah:"toto", toto:"bibi", tutu:109, annonce_fr:"Bonne fêtes
> de fin d'année !", annonce_en:"Happy new year, this is the end of the year
> 2005...Hello 2006 !!"})
> ---------------[/color]

No, it will not always, unless toSource() is user-defined.
[color=blue]
> if you want the same functionality in any browser[/color]

You meant to say "with any script engine" but even that would not be true.
[color=blue]
> you can also use my
> core2 library
> http://www.burrrn.com/projects/core2.html
>
> here an exemple
> ---------------
> <html>
> <body>
> <head>[/color]

Invalid examples are worthless. <URL:http://validator.w3.org/>
[color=blue]
> will trace in the DIV[/color]

IMHO, "tracing" is following traces, such as a stack trace where one call
on the stack leads to the next. So I do not see any tracing here, let alone
the "core2" library fulfilling its self-imposed requirement of "same API
everywhere (JavaScript, JScript, ActionScript, etc.)", considering e.g.
the untested use of document.getElementById() and proprietary `.innerHTML'.
I also see other examples of bad code style: an undeclared variable just to
call a function and then `delete' it, bad indentation, error-prone property
inference and so on. Certainly something that will make your day
interesting.


PointedEars
___________
[1] See <URL:http://en.wikipedia.org/wiki/Trace>, Computing, which you often
like to refer to on your Web site.
Dec 27 '05 #20

VK
P: n/a
VK
[color=blue][color=green]
> > VK wrote:
> > It does... until when... because any JavaScript/JScript objext extends
> > Object constructor.[/color][/color]
[color=blue]
>Thomas 'PointedEars' Lahn wrote:
> Wrong. What you maybe meant to say was that user-defined objects
> inherit properties from the Object prototype which would be disabled
> for an inheriting object as long as their name would be used as name
> of a property of that object.[/color]

Programming entities: Evolutionism or Creationism? :-)

I'm staing exclusively on the Evolutionism position here. There is the
initial protozoa Object() and everything else are branches of evolution
from this starting point. Date(), String(), Array(), myObject(),
myOtherObject() are all equally coming that protozoa despite their
evolution branches (thus property sets) can be twisted in the most
amazing ways.

Therefore arguments like "Array() is almost like Object() so no big
deal what to use" to me sounds like "daschund is really same kind as
buldog so no big deal what to buy".

I accept the possibility of other theories including the promoted
Selective Creationism, there all things are by themselves, and some
things should be considered as one entity (despite some differences)
because they've been created by Them to be one thing.

I still believe that my God is better :-)
[color=blue]
> Nothing is "overloaded" here.[/color]
I guess my usage of "overload" is not canonical. For me it's a way to
use the "other side" of things. Like create Array() and use it as
associative array via Object() side. Or store Function() arguments in
its Object() background (like in my sample), or force plus to works as
minus - something like this.

Dec 27 '05 #21

Thomas 'PointedEars' Lahn
P: n/a
Thomas 'PointedEars' Lahn
VK wrote:
[color=blue][color=green][color=darkred]
>> > VK wrote:
>> > It does... until when... because any JavaScript/JScript objext extends
>> > Object constructor.[/color][/color]
>[color=green]
>> Thomas 'PointedEars' Lahn wrote:[/color][/color]

I thought you finally learned how to quote.
[color=blue][color=green]
>> Wrong. What you maybe meant to say was that user-defined objects
>> inherit properties from the Object prototype which would be disabled
>> for an inheriting object as long as their name would be used as name
>> of a property of that object.[/color]
>
> Programming entities: Evolutionism or Creationism? :-)[/color]

That is not a matter of philosophy or belief. The statement that
"JavaScript/JScript obje[c]t extends [the] Object constructor" is
simply wrong.
[color=blue][color=green]
>> Nothing is "overloaded" here.[/color]
> I guess my usage of "overload" is not canonical. [...][/color]

Surprise, surprise!


PointedEars
Dec 27 '05 #22

zwetan
P: n/a
zwetan
"Thomas 'PointedEars' Lahn" wrote:
[color=blue]
> zwetan wrote:
>[color=green][color=darkred]
> >> Well, I would like to obtain a list of all JavaScript var statement,
> >> With "for...in" perharps ?[/color][/color]
>
> Please provide attribution of quoted material:
>
> <URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>[/color]

from my post I think is pretty clear to whom I answser (1 single poster)
cf
"Material quoted from the previous message is attributed to its author and
indented with a marker character (usually >). "

anyway point taken as you can see in the first line of this post.


[color=blue]
>
> Probably you meant to say "There are no associative Arrays in[/color]
JS/ECMAScript.[color=blue]
> What is achieved with associative arrays in other languages, is provided[/color]
by[color=blue]
> properties of objects and property accessors here."
>[/color]

Well I didn't get into all the details indeed,
yes there are no real associative Array in ECMAScript,
but you can obtain a similar functionality of associative Array using object
Object

but as I prefer to stay on topic, which if I remember well was
"I would like to obtain a list of all JavaScript var statement"

why should I go all the way to explain in lenghty details
the subtle differences between associative arrays and indexed arrays ?

Why don't you go into those details if you think these explanations are
missing
and should be stated to undertand better the problem at stake ?

for people interested in all the subtleties of Arrays in ECMAScript
I would advise those links
http://blogs.msdn.com/ericlippert/ar.../10/53376.aspx
http://blogs.msdn.com/ericlippert/ar.../12/53377.aspx
http://blogs.msdn.com/ericlippert/ar.../14/53383.aspx
http://blogs.msdn.com/ericlippert/ar.../21/53399.aspx
http://blogs.msdn.com/ericlippert/ar.../05/53452.aspx

Eric Lippert talk about the difference of implementation of Arrays in
JScript.NET
compared to JScript, but it can still be very usefull to apply this
knowledge
in other ECMAScript hosts, but as you can see the topic can be quite
lengthy.

[color=blue][color=green]
> > in FF for ex:[/color][/color]
[snip][color=blue]
>
> No, it will not always, unless toSource() is user-defined.
>[/color]

"in FF" mean "in FireFox"...
you don't need to define the toSource method in FireFox afaik
it's natively implemented in the SpiderMonkey engine.
(and please don't point that I don't provide the exact version of the
engine)

I could understand that someone could not be familiar with the "FF"
abbreviation,
but to attribute my use of this abbreviation as a way to make a false
statement
is going a little too far don't you think ?

[color=blue][color=green]
> > if you want the same functionality in any browser[/color]
>
> You meant to say "with any script engine" but even that would not be true.[/color]

you know I just posted a comment to help someone,
I can not really phrase all my comments to suit your taste.

I meant "any browser" as "any browser host", as "any browser host
implementing ECMA-262 standard",
and I think you are really picky to jump on a detail like that.

Can you precise in what way "even that would not be true" ?
is it because of older browsers not implementing fully ECMA-262 3rd edition
or other browsers not implementing at all ECMA-262 and so not being able
to execute JavaScript ?

If for you my lack of details in my comment cause a problem,
you should a least apply this principle to your own comments,
just to not be vague as you apparently repproaching me.

I can accept critics, the problem with your comments is that you don't
explain clearly what your critic is about...

Yes off course "in any browser" was vague, but com'on
you know as me that not all ECMAScript implementations are made the same,
to discuss the problem of compatibility amongs all the browsers is a very
long thread in itself, I was just focusing on the problem that's all.

[color=blue][color=green]
> > you can also use my
> > core2 library
> > http://www.burrrn.com/projects/core2.html
> >
> > here an exemple
> > ---------------
> > <html>
> > <body>
> > <head>[/color]
>
> Invalid examples are worthless. <URL:http://validator.w3.org/>[/color]

at least I provide an exemple, and yes I don't pass all code that I write
from the top of my head trough a validator first

as I don't syntax check all my newsgroups post

I inverted 2 HTML tags..big deal
as sometimes I can inverse letters in words too because I write too fast
hey I'm just human

What is worhtless imho is someone spending his valuable time
pointing finger to all my little errors as if every human were robots and
perfect

are we here to help someone solve a problem
or to start a fight on what is worthless or not ?

[color=blue]
>[color=green]
> > will trace in the DIV[/color]
>
> IMHO, "tracing" is following traces, such as a stack trace where one call
> on the stack leads to the next. So I do not see any tracing here, let[/color]
alone[color=blue]
> the "core2" library fulfilling its self-imposed requirement of "same API
> everywhere (JavaScript, JScript, ActionScript, etc.)", considering e.g.
> the untested use of document.getElementById() and proprietary[/color]
`.innerHTML'.

You see "tracing" in a different way that I see it and also in a different
context.

core2 goal is to be able to run anywhere there is a compliant ECMA-262
interpreter,
you can not implement "stack trace" everywhere due to the ECMA-262 standard
itself
which let the implementation of Function.prototype.toString at the
discretion of the
implementors.

Some hosts can introspect function body, some other hosts can not do that,
that's why the choice of not implementing "stack trace" has been made.
It's a choice that fill the requirement of the library, if that philosophy
does not suit you
well the code is open source and you are free to make a patch/diff/fork/etc.
..

And even if it could have been possible to implement "stack trace" for every
host,
I would have named it as a global function "StackTrace" to show the
difference of behaviour.

core2 is also a library which focus on ECMAScript programming, not the DOM
programming.

If you had taken the time to read some comments on the code,
http://live.burrrn.com/browser/ECMA-...uRRRn/core2.js
you could haves seen this
" yes it's an ugly hack :) "

I don't claim at all that the trace function is efficient, I just claim it
works
as it is on those browsers and as an ugly hack
a.. Mozilla, FireFox v1.0 (Windows)
b.. Mozilla, Mozilla v1.7.5 (Windows)
c.. Microsoft, Internet Explorer v6.0 (Windows)
d.. Opera Software, Opera v8.5 (Windows)
so yes I don't test getElementById(), I test ECMAScript code
targeted to work in any ECMA-262 environments, not only browser DOM.

And yes the library does not work as it is for IE v5.0
or is not yet tested on some other hosts, etc.

It is clearly stated on the project page and then i don't think I induce
people in error.

Following some of your links I see that you have developped libraries on
your own also,
so I suppose you know that sometimes you have to make choices about what
features to implement or not and to what extend to implement them and to how
to implement them.

[color=blue]
> I also see other examples of bad code style:
> an undeclared variable just to call a function and then `delete' it,[/color]

does this cause a bug ?
[color=blue]
>bad indentation,[/color]

did you realize that the LIB releases have indeed their indentation striped
out
(as uncessary empty lines and code comments)
because their sole purpose are to be used as LIBraries,
if you want clean indented code with comments and all
you can check the DEVelopper releases,
or directly the source code in SVN.

[color=blue]
> error-prone property inference and so on.[/color]

I would have been glad that you had filled a bug report if you had seen
errors or bugs
http://live.burrrn.com/newticket

but afaik with the current code base and the current sets of unit tests and
the current tested hosts
I don't see any property inference, so if you can point where you see such
an error happening
I would just be happy to correct it.

If this comment is more about a difference of coding style, well...
I read some of your codes, you got your coding style
I understand why you do things like that
and I would not see myself to tell you that your coding style is bad
simply because you don't do things as I do.

The merit of a coding style is to be coherent amongs the whole code,
you are coherent amongs your code, I am coherent amongs my code,
doing things differently does not mean one way is better than another,
it's just a coding style.
[color=blue]
> Certainly something that will make your day interesting.[/color]

I understand that you are posting here for a long time and I respect that
but even if that was my 1st post on this newsgroup (which is not the case)
I don't really find all your comments on this particular topic that much
interesting

I would have prefered more constructive comments, but that's just me.
[color=blue]
> ___________
> [1] See <URL:http://en.wikipedia.org/wiki/Trace>, Computing, which you[/color]
often[color=blue]
> like to refer to on your Web site.[/color]

indeed the first line I read is "The word trace has several meanings" :)

with a little advance I wish you an happy new year 2006 PointedEars

live long and prosper

zwetan


Dec 28 '05 #23

Thomas 'PointedEars' Lahn
P: n/a
Thomas 'PointedEars' Lahn
zwetan wrote:
[color=blue]
> "Thomas 'PointedEars' Lahn" wrote:[color=green]
>> zwetan wrote:
>> [...]
>> Probably you meant to say "There are no associative Arrays in[/color]
> JS/ECMAScript.[/color]
^^^^
Please get your NetNews posting software repaired:

<URL:http://insideoe.com/>

[repaired broken quotes][color=blue][color=green]
>> What is achieved with associative arrays in other languages, is provided
>> by properties of objects and property accessors here."[/color]
>
> Well I didn't get into all the details indeed,
> yes there are no real associative Array in ECMAScript,
> but you can obtain a similar functionality of associative Array using
> object Object
>
> but as I prefer to stay on topic,[/color]

This is on-topic as long it is about JS/ECMAScript.
[color=blue]
> which if I remember well was "I would like to obtain a list of all
> JavaScript var statement"
>
> why should I go all the way to explain in lenghty details
> the subtle differences between associative arrays and indexed arrays ?[/color]

Why should you provide something that returns the names of properties
of an object when the question was about `var' statements?

var x, y, z;

should be _one_ entry in the requested list. Of course that is not possible
with property accessors.
[color=blue]
> Why don't you go into those details if you think these explanations are
> missing and should be stated to undertand better the problem at stake ?[/color]

Because it has already been discussed at great length here before.
[color=blue]
> [...][color=green][color=darkred]
>> > in FF for ex:[/color]
>> No, it will not always, unless toSource() is user-defined.[/color]
>
> "in FF" mean "in FireFox"...[/color]

It does not work this way in Firefox (1.5) without prototype augmentation,
or in JavaScript for that matter, and it never has.
[color=blue]
> you don't need to define the toSource method in FireFox afaik[/color]

True, there is native prototype.toSource() for several core objects but
it does returns something different than you suggest in all cases.
[color=blue]
> it's natively implemented in the SpiderMonkey engine.[/color]

Yes, but it does not do what you suggest.
[color=blue]
> (and please don't point that I don't provide the exact version of the
> engine)[/color]

It does not and has never worked this way in any SpiderMonkey version.
[color=blue][color=green][color=darkred]
>> > if you want the same functionality in any browser[/color]
>> You meant to say "with any script engine" but even that would not be
>> true.[/color]
>
> you know I just posted a comment to help someone,
> I can not really phrase all my comments to suit your taste.[/color]

Usage of exact terms are one important key to understanding.
[color=blue]
> I meant "any browser" as "any browser host", as "any browser host
> implementing ECMA-262 standard", [...][/color]

It would have been true if you wrote "any language that is an
ECMAScript _3_ implementation." What is a "browser host" anyway?
[color=blue]
> Can you precise in what way "even that would not be true" ?
> is it because of older browsers not implementing fully ECMA-262 3rd
> edition or other browsers not implementing at all ECMA-262[/color]

Yes.
[color=blue]
> and so not being able to execute JavaScript ?[/color]

The question conveys a misconception about ECMAScript and JavaScript.
ECMAScript (3) !== JavaScript (1.5).
[color=blue][color=green][color=darkred]
>> > you can also use my
>> > core2 library
>> > http://www.burrrn.com/projects/core2.html
>> >
>> > here an exemple
>> > ---------------
>> > <html>
>> > <body>
>> > <head>[/color]
>>
>> Invalid examples are worthless. <URL:http://validator.w3.org/>[/color]
>
> at least I provide an exemple, and yes I don't pass all code that I write
> from the top of my head trough a validator first[/color]

If you are not able to write Valid markup from the top of your head (which
is a sure sign of insufficient experience), you should validate the result
first, because bad examples are copied by the uninitiated and end up in bad
code.
[color=blue]
> as I don't syntax check all my newsgroups post[/color]

I do not either. That is not the point.
[color=blue]
> I inverted 2 HTML tags..big deal
> as sometimes I can inverse letters in words too because I write too fast
> hey I'm just human[/color]

The rest of your markup is not Valid, too.
[color=blue]
> What is worhtless imho is someone spending his valuable time
> pointing finger to all my little errors as if every human were
> robots and perfect[/color]

/You/ _posted_ the example.
[color=blue]
> are we here to help someone solve a problem
> or to start a fight on what is worthless or not ?[/color]

Examples with not Valid markup are worthless, because script code can only
operate reliably on Valid markup. That is a fact, not something that can
or should be fought about.
[color=blue][color=green][color=darkred]
>> > will trace in the DIV[/color]
>>
>> IMHO, "tracing" is following traces, such as a stack trace where one call
>> on the stack leads to the next. So I do not see any tracing here, let
>> alone the "core2" library fulfilling its self-imposed requirement of
>> "same API everywhere (JavaScript, JScript, ActionScript, etc.)",
>> considering e.g. the untested use of document.getElementById() and
>> proprietary `.innerHTML'.[/color]
>
> You see "tracing" in a different way that I see it and also in a different
> context.[/color]

You are misusing the word. There is nothing traced here at all. Maybe
I would have concured if you provided a serialization of the properties,
that is, show what steps are executed or serialize each known property
value (including those that are not enumerable) until there would only
be primitive values. That would be some kind of tracing, following the
trace from one property to the primitive value. So a trace of

x = {y: [/z/]};

could look like

x = new Object();
x.y = new Array();
x.y[0] = new RegExp("z");

or

x = {
y: Array
{
"0": RegExp
{
...
source: "z"
...
},
length: 1
...
}
};
[color=blue]
> core2 goal is to be able to run anywhere there is a compliant ECMA-262
> interpreter,[/color]

An implementation conforming to ECMAScript _Edition 3_.
[color=blue]
> [...][/color]

You are winding around the issue.
[color=blue][color=green]
>> I also see other examples of bad code style:
>> an undeclared variable just to call a function and then `delete' it,[/color]
>
> does this cause a bug ?[/color]

No, but it rightfully causes a warning in the JavaScript console. Variables
should be declared. With your code, assuming an ECMAScript 3 compliant
script engine is used,

(function(...)
{
// ...
})(...);

sufficed. There is no need for the undeclared global variable, hence
no need for `delete'.
[color=blue][color=green]
>> bad indentation,[/color]
>
> did you realize that the LIB releases have indeed their indentation
> striped out
> (as uncessary empty lines and code comments)[/color]

No, but that is not the point. You should and could have stripped it
better then.
[color=blue]
> because their sole purpose are to be used as LIBraries,
> if you want clean indented code with comments and all
> you can check the DEVelopper releases,
> or directly the source code in SVN.[/color]

What are you talking about?

The developer release is just as badly indented:

| _global.trace = function( txt )
| {
| txt = String( txt );
| /* note:
| if you want to trace in a DIV layer inside the HTML page.
| Better if you want to trace a lot in the large.
| (yes it's an ugly hack :))

An ugly hack that is unnecessary, for `textarea' elements exist.

| */
| var tc = document.getElementById( "TraceConsole" );
| var clean = tc.innerHTML.replace( "<pre>", "" );
| clean = clean.replace( "</pre>", "" );
| tc.innerHTML = "<pre>"+clean+txt+"\r\n"+"</pre>";
| /* note:
| if you want to trace outside of the HTML page.
| Better for very few localized trace.
| */
| }
[color=blue][color=green]
>> error-prone property inference and so on.[/color]
>
> [...]
> but afaik with the current code base and the current sets of unit tests
> and the current tested hosts
> I don't see any property inference, so if you can point where you see
> such an error happening
> I would just be happy to correct it.[/color]

The problem is that you tested with certain host environments and infer
from those special cases to the general one. What your code is lacking
to be almost bullet-proof is a feature-test _on run-time_ that the used
features, particularly the used DOM features, are supported.
[color=blue]
> [...]
> The merit of a coding style is to be coherent amongs the whole code,
> you are coherent amongs your code, I am coherent amongs my code,
> doing things differently does not mean one way is better than another,
> it's just a coding style.[/color]

That is not entirely true. Bad code style usually is based on
misconceptions and often results in unreliable code and/or code
that is harder to maintain.

I could provide more examples of that right from your code, but
that would not be worth the time required to be invested.
[color=blue][color=green]
>> ___________
>> [1] See <URL:http://en.wikipedia.org/wiki/Trace>, Computing, which you[/color]
> often[color=green]
>> like to refer to on your Web site.[/color]
>
> indeed the first line I read is "The word trace has several meanings" :)[/color]

We are talking about applied computer science, do we not?
[color=blue]
> with a little advance I wish you an happy new year 2006 PointedEars
> live long and prosper[/color]

Thanks, you too.


PointedEars
Dec 28 '05 #24

Thierry Loiseau
P: n/a
Thierry Loiseau
Jasen Betts <jasen@free.net.nospam.nz> wrote:
[color=blue]
> I know very little French, "Etat" is like the english word "nation" ???[/color]

Yep ! Sorry, I would like to write "état". Of course !-)
Zwetan, comment traduis-tu ce terme ?

Merci beaucoup à tous !

Thierry
Dec 28 '05 #25

35 Replies

Post your reply

Help answer this question



Didn't find the answer to your JavaScript / Ajax / DHTML question?

You can also browse similar questions: JavaScript / Ajax / DHTML