[links-list] Re: javascript parse question.

Martin Pergel mper7437 at artax.karlin.mff.cuni.cz
Fri Jun 7 05:44:01 PDT 2002


On Thu, 6 Jun 2002, Dave Mielke wrote:

> [quoted lines by Zhao, Jing on June 6, 2002, at 14:58]
> >  'trim' function is as followed:
> I never did learn JavaScript very well, but here are a few observations:
> >    var len =   value.length;
> >
> >    index   =   0;
> Which is the correct syntax? Both of these lines appear to be defining a local
> variable, but one says "var" and one doesn't. Perhaps some browsers support
> both forms but links only supports one of them.

     specification, that I found and tried to implement, says, that:
"var a=5;" creates local variable named 'a' and assigns 5 into it. After
this construction in the function, identifier 'a' will mean the local one.
If you use only a=5; then there is used "most local" variable which is
found. If there is found none, there is created a global one. BTW
according to specification of Javascript 1.1 (which I implemented) var a=5
is the same as this.a=5, so beware of trying to use "this" object as in
C++ (it completely differs from the implementation in Javascript 1.3 whose
specification I found a few months ago).

     If you try following script, you should and in my version of Links
you obtain results 1, 5, 1:
function f()
{       alert(a);
        var a=5;

> >    for(i=0;i<len;i++)
> >    {
> >        if(value.charAt(i)  !=  " ")
> >        {
> >            i   =   len;
> Why not use "break" here? My guess is that JavaScript has such a statement.
> >    for(i=len-1;i>=0;i--)
> >    {
> >        if(value.charAt(i)  !=  " ")
> >        {
> >            i   =   -1;
> Again, why not use "break" here?

     One can write programs in many ways e. g. in a structured way which
in my oppinion doesn't like statements like break or continue, although
Javascript has such statements (and now they should be implemented
correctly in Links interpret).

     Have a nice day

rEmark: In new version there will be more dirty tricks enabled, e. g.
against specification invalid argument by function charAt won't cause
error, as I found that a lot of people don't check the length and ask for
character after the end of the string in Javascript. B-( Try to do this in
C-programming-language. B-)

Unsubscribe: send email to links-list-request at linuxfromscratch.org
and put unsubscribe in the subject header of the message

More information about the links-list mailing list