On Nov 27, 5:58 am, codz wrote:
> hello everyone,
>
> i just want to ask anybody about this warning that
> always show whenever my page load with the jquery.js file.
>
> Warning:
>
> test for equality (==) mistyped as assignment (=)?
> Source File:http://localhost:2008/jquery.js
> Line: 1161, Column: 32
> Source Code:
>    while ( elem = second[ i++ ] )

For a very long time it has been a common error in javascript to write
a single equals sign when attempting comparison. It can be a
misconception (where novices are concerned), a typo from even very
experienced javascript authors or, say, a momentary laps of
concentration from someone who switches between many languages
regularly.

So when Firefox sees an assignment operation in a context where
comparison would be more expected (such as the expressions for - if -,
- while - and so on) it puts up this warning to make it easier for the
programmer to find their mistakes.

One way of handling this to impose a bit of code 'style' discipline;
if you mean to use assignment in the expression of an - if -, - while
-, etc. statement you wrap parentheses around it. Thus - while ( elem
= second[ i++ ] ) - becomes - while ( (elem = second[ i++ ]) ) - and
then warnings stop. Thus the (otherwise superfluous) parentheses
perform two functions; they stop the warning and they act as a flag to
indicate that you really meant to be doing assignment instead of
comparison. Meaning that when you see assignment in one of those
contexts without the wrapping parentheses it would be correct to start
of suspecting a programmer error, while without the parentheses every
occurrence of a single equals sign in and - if - expressions looks
suspicious.

> anonymous function does not always return a value

That statement is technically false. All javascript function calls
return a value (always). If they don't return through an explicit
return statement then they return the undefined value (which is still
a value in javascript), if they return through a return statement that
does not have an expression then they also return the undefined value,
else they return through a return statement that has an expression and
the function call returns the value of that expression (which may
still be the undefined value).

Firefox's 'warnings' often make statements that are factually false.

This warning is about promoting a particular 'style' in code
authoring; it is felt that if any path through a function's code ends
in an explicit return statement (and especially one with an
expression)  then all possible paths through that function's code
should end with such a statement. It can be seen as an expression of
the completeness of the author's perception of the logic of the code
in the function; he/she has perceived all the possible paths through
the function (marking the end of each with an explicit return
statement), and so has not failed to observe some of the ways out of
the function.

'Style' (if not externally imposed (by, for example, an employer)) is
often seen as a matter of opinion and personal judgment. Personally I
like this particular style rule, but many others do not. I don't
particularly like the fact that Firefox/JavaScript(tm) elect to tell a
lie in there attempt to promote it. That is probably
counterproductive.

The thing to do with code 'style' rules is to apply critical judgment
to the rationale behind them and see what you think of the reasoning.
If you are convinced you will use them, and if the arguments are not
convincing then the 'rule' probably was not worth that much to start
with.

> Source File:http://localhost:2008/jquery.js
> Line: 1859, Column: 71
> Source Code:
>    });
>
> anonymous function does not always return a value
> Source File:http://localhost:2008/jquery.js
> Line: 3524, Column: 20
> Source Code:
>     this[0][ method ];
>
> though this warning show, it does not affect my entire
> program.

No, everything should run just the same, though probably very
fractionally slower as it must take some time to recognise the
subjects of the warnings and make the reports of those warnings.

> i hope that all of you can make me understand about this
> or maybe solve this stuff.

There is nothing to solve, they are just warnings. It is errors that
you should worry about, and if the warnings start to get in the way of
seeing the errors filter the warnings out.

Reply via email to