Skip to search.

Breaking News Visit Yahoo! News for the latest.

×Close this window

jslint_com · This group has moved to Google Plus.

The Yahoo! Groups Product Blog

Check it out!

Group Information

  • Members: 584
  • Category: JavaScript
  • Founded: Mar 7, 2008
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Messages

Advanced
Messages Help
Messages 1683 - 1712 of 3202   Oldest  |  < Older  |  Newer >  |  Newest
Messages: Show Message Summaries Sort by Date ^  
#1683 From: "Douglas Crockford" <douglas@...>
Date: Mon Dec 13, 2010 11:26 pm
Subject: Re: [jslint] option.strict
douglascrock...
Send Email Send Email
 
--- In jslint_com@yahoogroups.com, "Rob Richardson" <erobrich@...> wrote:
>
> You've specified "at the top of the file" twice.  Did you intend to identify
> the second as "the top of a function"?

Yes.

#1684 From: AJ ONeal <coolaj86@...>
Date: Mon Dec 13, 2010 11:36 pm
Subject: Re: [jslint] option.strict
coolaj86
Send Email Send Email
 
FYI, "at the top of" means "inside", not "on top".
That's why I was originally confused.

// Non-strict code...

(function(){
   "use strict";

   // Define your library strictly...
})();

// Non-strict code...


http://stackoverflow.com/questions/1335851/what-does-use-strict-do-in-javascript\
-and-what-is-the-reasoning-behind-it


I believe this would be a useless statement (though I'm not sure).
In any case it's probably best to avoid it.


(function(){

   // do stuff
}());

"use strict";

(function(){

   // do stuff
})();


AJ ONeal


On Mon, Dec 13, 2010 at 4:26 PM, Douglas Crockford <douglas@...>wrote:

>
>
> --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>, "Rob
> Richardson" <erobrich@...> wrote:
> >
> > You've specified "at the top of the file" twice. Did you intend to
> identify
> > the second as "the top of a function"?
>
> Yes.
>
>
>


[Non-text portions of this message have been removed]

#1685 From: "Jakob Kruse" <kruse@...>
Date: Tue Dec 14, 2010 8:06 am
Subject: Re: [jslint] option.strict
thekrucible
Send Email Send Email
 
In your second example, "use strict"; is neither at the top of a file or at the
top of a function, thus it has no effect.


/Jakob

   _____

From: AJ ONeal [mailto:coolaj86@...]
To: jslint_com@yahoogroups.com
Sent: Tue, 14 Dec 2010 00:36:05 +0100
Subject: Re: [jslint] option.strict

FYI, "at the top of" means "inside", not "on top".
   That's why I was originally confused.

   // Non-strict code...

   (function(){
     "use strict";

     // Define your library strictly...
   })();

   // Non-strict code...


  
http://stackoverflow.com/questions/1335851/what-does-use-strict-do-in-javascript\
-and-what-is-the-reasoning-behind-it


   I believe this would be a useless statement (though I'm not sure).
   In any case it's probably best to avoid it.


   (function(){

     // do stuff
   }());

   "use strict";

   (function(){

     // do stuff
   })();


   AJ ONeal


   On Mon, Dec 13, 2010 at 4:26 PM, Douglas Crockford
<douglas@...>wrote:

   >
   >
   > --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>, "Rob
   > Richardson" <erobrich@...> wrote:
   > >
   > > You've specified "at the top of the file" twice. Did you intend to
   > identify
   > > the second as "the top of a function"?
   >
   > Yes.
   >
   >
   >


   [Non-text portions of this message have been removed]



   ------------------------------------

   Yahoo! Groups Links





[Non-text portions of this message have been removed]

#1686 From: "Douglas Crockford" <douglas@...>
Date: Tue Dec 14, 2010 10:56 pm
Subject: Strict mode is coming to town
douglascrock...
Send Email Send Email
 
JSLint is now recommending the function form of strict pragma and not the file
form. So

     "use strict";
     ...

is out, and

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

is in.

See also http://www.yuiblog.com/blog/2010/12/14/strict-mode-is-coming-to-town/

#1687 From: "abyssoft@..." <abyssoft@...>
Date: Tue Dec 14, 2010 11:17 pm
Subject: Re: Strict mode is coming to town
abyssoft...
Send Email Send Email
 
This change is a paradigm level change.

This causes all of my scripts to now complain.
While after having read the article I believe this be the best practice; I
believe this should be an option for the time being, to allow for a transition
period, so people can get used to the idea.

Whilst JSLint may hurt ones feelings in order to make one a better programmer,
it should not leave one feeling dirty, and abused.

#1688 From: "Douglas Crockford" <douglas@...>
Date: Tue Dec 14, 2010 11:26 pm
Subject: Re: Strict mode is coming to town
douglascrock...
Send Email Send Email
 
--- In jslint_com@yahoogroups.com, "abyssoft@..." <abyssoft@...> wrote:
> This change is a paradigm level change.
>
> This causes all of my scripts to now complain.
> While after having read the article I believe this be the best practice; I
believe this should be an option for the time being, to allow for a transition
period, so people can get used to the idea.
>
> Whilst JSLint may hurt ones feelings in order to make one a better programmer,
it should not leave one feeling dirty, and abused.


     Your sadly pathetic bleatings are harshing my mellow.

#1689 From: "Douglas Crockford" <douglas@...>
Date: Tue Dec 21, 2010 9:42 pm
Subject: Re: SV: [jslint] problems with Nesting
douglascrock...
Send Email Send Email
 
--- In jslint_com@yahoogroups.com, "Jakob Kruse" <kruse@...> wrote:
>
> JSLint (with the strict whitespace option) does not support the way you write
an array. Specifically it does support a line break after a comma, but not
between the last array element and the end brace. This leads to the "wrong
indentation" error.
>
> /Jakob
>
>
> Fra: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] På vegne
af abyssoft@...
> Sendt: 22. november 2010 00:20
> Til: jslint_com@yahoogroups.com
> Emne: [jslint] problems with Nesting
>
>
> given the following snippet where » are tabs (4 space) and ---------- are
begin and end markers. (the blank line after the start marker is intentional)
>
> ----------
>
> "use strict";
> //Library (Netsuite Objects)
> /*global NlobjAssistant, NlobjAssistantStep, NlobjButton, NlobjColumn,
NlobjConfiguration, NlobjContext, NlobjError, NlobjField, NlobjFieldGroup,
NlobjFile, NlobjForm, NlobjList, NlobjPortlet, NlobjRecord, NlobjRecord,
NlobjRequest, NlobjResponse, NlobjSearchColumn, NlobjSearchFilter,
NlobjSearchResult, NlobjSelectOption, NlobjSubList, NlobjTab
> */
> //Library (Netsuite API)
> /*global nlapiSearchRecord
> */
> //Library (IS_library_V2_00)
> /*global Global
> */
> var searchResults = nlapiSearchRecord(
> »'customrecord_is_module_codes',
> »null,
> »[
> »»new NlobjSearchFilter(
> »»»'internalid',
> »»»null,
> »»»"noneof",
> »»»[
> »»»»29,
> »»»»31,
> »»»»32,
> »»»»33
> »»»]
> »»)
> »]
> );
> ----------
>
> JSLint responds with a rather unexpected error
>
> Problem at line 27 character 5: Expected ']' to have an indentation at 9
instead at 5.


Thanks. Please try it now.

In the future, please try to refine the problem text in bug reports. It is
greatly appreciated if you try to make the example that demonstrates the problem
as small as possible.

#1690 From: "abyssoft@..." <abyssoft@...>
Date: Tue Dec 21, 2010 11:23 pm
Subject: Re: SV: [jslint] problems with Nesting
abyssoft...
Send Email Send Email
 
Works now.
Thank you.


--- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
>
> --- In jslint_com@yahoogroups.com, "Jakob Kruse" <kruse@> wrote:
> >
> > JSLint (with the strict whitespace option) does not support the way you
write an array. Specifically it does support a line break after a comma, but not
between the last array element and the end brace. This leads to the "wrong
indentation" error.
> >
> > /Jakob
> >
> >
> > Fra: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] På vegne
af abyssoft@
> > Sendt: 22. november 2010 00:20
> > Til: jslint_com@yahoogroups.com
> > Emne: [jslint] problems with Nesting
> >
> >
> > given the following snippet where » are tabs (4 space) and ---------- are
begin and end markers. (the blank line after the start marker is intentional)
> >
> > ----------
> >
> > "use strict";
> > //Library (Netsuite Objects)
> > /*global NlobjAssistant, NlobjAssistantStep, NlobjButton, NlobjColumn,
NlobjConfiguration, NlobjContext, NlobjError, NlobjField, NlobjFieldGroup,
NlobjFile, NlobjForm, NlobjList, NlobjPortlet, NlobjRecord, NlobjRecord,
NlobjRequest, NlobjResponse, NlobjSearchColumn, NlobjSearchFilter,
NlobjSearchResult, NlobjSelectOption, NlobjSubList, NlobjTab
> > */
> > //Library (Netsuite API)
> > /*global nlapiSearchRecord
> > */
> > //Library (IS_library_V2_00)
> > /*global Global
> > */
> > var searchResults = nlapiSearchRecord(
> > »'customrecord_is_module_codes',
> > »null,
> > »[
> > »»new NlobjSearchFilter(
> > »»»'internalid',
> > »»»null,
> > »»»"noneof",
> > »»»[
> > »»»»29,
> > »»»»31,
> > »»»»32,
> > »»»»33
> > »»»]
> > »»)
> > »]
> > );
> > ----------
> >
> > JSLint responds with a rather unexpected error
> >
> > Problem at line 27 character 5: Expected ']' to have an indentation at 9
instead at 5.
>
>
> Thanks. Please try it now.
>
> In the future, please try to refine the problem text in bug reports. It is
greatly appreciated if you try to make the example that demonstrates the problem
as small as possible.
>

#1691 From: "kipenzam" <kipenzam@...>
Date: Tue Dec 28, 2010 3:02 pm
Subject: question on JSLint
kipenzam
Send Email Send Email
 
Hello,

I have linted my program, and got this error :

Problem at line 6 character 45: Insecure '.'.

var reg = type === 'html' ? /<!--.*?-->/g: /\/\*.*?\*\//g;
(If you see \, that is backslash)

I've tried uncaptured group(?:.*)? for that, got same error.


then how can I use characters like . ^ in regexp with secure? please help

#1692 From: "Douglas Crockford" <douglas@...>
Date: Tue Dec 28, 2010 5:43 pm
Subject: Re: question on JSLint
douglascrock...
Send Email Send Email
 
--- In jslint_com@yahoogroups.com, "kipenzam" <kipenzam@...> wrote:
> I have linted my program, and got this error :
>
> Problem at line 6 character 45: Insecure '.'.
>
> var reg = type === 'html' ? /<!--.*?-->/g: /\/\*.*?\*\//g;
> (If you see \, that is backslash)
>
> I've tried uncaptured group(?:.*)? for that, got same error.
>
>
> then how can I use characters like . ^ in regexp with secure? please help

Turn off the secure regexp option, or enumerate the set of characters that .
should match.

#1693 From: "biggeleben" <biggeleben@...>
Date: Wed Dec 29, 2010 10:46 pm
Subject: Strict white space bug?
biggeleben
Send Email Send Email
 
Hi,

after hours of figuring out why my code fails JSLINT's validation (edition
2010-12-23), I decided to post here. The original code uses some jQuery chains,
but I will give some simplified examples in the following that focus on "strict
white space".

The first example works - of course:

/*jslint white: true */
/*globals one, two */

one(
     two()
);

Now, we extend this example by adding options to the second function:

/*jslint white: true */
/*globals one, two */

one(
     two({
         works: true
     })
);

Next, we add a third function. This example still passes the validation:

/*jslint white: true */
/*globals one, two, three */

one(
     two(
         three()
     )
);

No surprises so far. However, the next code will fail, although it's analog to
the second example:

/*jslint white: true */
/*globals one, two, three */

one(
     two(
         three({
             works: false
         })
     )
);

JSLINT says "Problem at line 7 character 13: Expected 'works' to have an
indentation at 5 instead at 13." and "Problem at line 8 character 9: Expected
'}' to have an indentation at 1 instead at 9."

Following these hints, we get the following messy code which actually passes the
validation:

/*jslint white: true */
/*globals one, two, three */

one(
     two(
         three({
     works: false
})
     )
);

For me, this is really strange, so that I even consider a bug in the latest
JSLINT code. Can anyone help me understanding this? Are there any recent changes
concerning JSLINT's indentation checks?

- Matthias

#1694 From: "biggeleben" <biggeleben@...>
Date: Wed Dec 29, 2010 11:14 pm
Subject: Re: Strict white space bug?
biggeleben
Send Email Send Email
 
Please use the "fixed width font" option to read my previous post properly.
Otherwise the indentation gets lost.

#1695 From: "kipenzam" <kipenzam@...>
Date: Thu Dec 30, 2010 1:27 am
Subject: a small problem is found
kipenzam
Send Email Send Email
 
Hello,

I coded like this:

(function () {
     Kip.shell2 = function (stream, reg, prefix, suffix) {
         return stream ? stream.replace(reg, function ($1) {
             return prefix + $1 + suffix;
         }): false;
     };
(more lines, of course)
}());

and got this:

Unused variable: reg 34 "anonymous"

the variable reg has scope on shell2, not the anonymous function.

#1696 From: "Douglas Crockford" <douglas@...>
Date: Thu Dec 30, 2010 2:18 am
Subject: Re: Strict white space bug?
douglascrock...
Send Email Send Email
 
--- In jslint_com@yahoogroups.com, "biggeleben" <biggeleben@...> wrote:
>
> Hi,
>
> after hours of figuring out why my code fails JSLINT's validation (edition
2010-12-23), I decided to post here. The original code uses some jQuery chains,
but I will give some simplified examples in the following that focus on "strict
white space".
>
> The first example works - of course:
>
> /*jslint white: true */
> /*globals one, two */
>
> one(
>     two()
> );
>
> Now, we extend this example by adding options to the second function:
>
> /*jslint white: true */
> /*globals one, two */
>
> one(
>     two({
>         works: true
>     })
> );
>
> Next, we add a third function. This example still passes the validation:
>
> /*jslint white: true */
> /*globals one, two, three */
>
> one(
>     two(
>         three()
>     )
> );
>
> No surprises so far. However, the next code will fail, although it's analog to
the second example:
>
> /*jslint white: true */
> /*globals one, two, three */
>
> one(
>     two(
>         three({
>             works: false
>         })
>     )
> );
>
> JSLINT says "Problem at line 7 character 13: Expected 'works' to have an
indentation at 5 instead at 13." and "Problem at line 8 character 9: Expected
'}' to have an indentation at 1 instead at 9."
>
> Following these hints, we get the following messy code which actually passes
the validation:
>
> /*jslint white: true */
> /*globals one, two, three */
>
> one(
>     two(
>         three({
>     works: false
> })
>     )
> );
>
> For me, this is really strange, so that I even consider a bug in the latest
JSLINT code. Can anyone help me understanding this? Are there any recent changes
concerning JSLINT's indentation checks?


JSLint doesn't like silly indentation schemes.
Turn off the Strict Whitespace option.

#1697 From: "Douglas Crockford" <douglas@...>
Date: Thu Dec 30, 2010 2:21 am
Subject: Re: a small problem is found
douglascrock...
Send Email Send Email
 
--- In jslint_com@yahoogroups.com, "kipenzam" <kipenzam@...> wrote:
> I coded like this:
>
> (function () {
>     Kip.shell2 = function (stream, reg, prefix, suffix) {
>         return stream ? stream.replace(reg, function ($1) {
>             return prefix + $1 + suffix;
>         }): false;
>     };
> (more lines, of course)
> }());
>
> and got this:
>
> Unused variable: reg 34 "anonymous"
>
> the variable reg has scope on shell2, not the anonymous function.

That's not the result I see. What aren't you telling us?

#1698 From: "duncan.cross@..." <duncan.cross@...>
Date: Thu Dec 30, 2010 2:58 am
Subject: break required at the end of a switch case even when redundant?
duncan.cross...
Send Email Send Email
 
If I have a switch case that ends with an if-block, and all of the if-block's
child statements end with either 'break' or 'return', like case 0 here:

  function testCase(i, j) {
    switch(i) {
      case 0:
        // ...
        if (j < 2) {
           // ...
           return 10;
        }
        else {
           // ...
           return 5;
        }
      case 1:
        // ...
        break;
    }
  }

... I'd expect to be able to omit the break before case 1, because the statement
would be unreachable. Adding a redundant one would feel kind of
counterproductive to the goal of improving code readability, but that is what
JSLint's error recommends. I do understand the point of not allowing
fall-through to catch a very common kind of mistake, but in cases like this,
there is no logical possibility of fall-through - or is there something I am
missing?

-Duncan

#1699 From: "Douglas Crockford" <douglas@...>
Date: Thu Dec 30, 2010 4:06 am
Subject: Re: break required at the end of a switch case even when redundant?
douglascrock...
Send Email Send Email
 
--- In jslint_com@yahoogroups.com, "duncan.cross@..." <duncan.cross@...> wrote:
>
> If I have a switch case that ends with an if-block, and all of the if-block's
child statements end with either 'break' or 'return', like case 0 here:
>
>  function testCase(i, j) {
>    switch(i) {
>      case 0:
>        // ...
>        if (j < 2) {
>           // ...
>           return 10;
>        }
>        else {
>           // ...
>           return 5;
>        }
>      case 1:
>        // ...
>        break;
>    }
>  }
>
> ... I'd expect to be able to omit the break before case 1, because the
statement would be unreachable. Adding a redundant one would feel kind of
counterproductive to the goal of improving code readability, but that is what
JSLint's error recommends. I do understand the point of not allowing
fall-through to catch a very common kind of mistake, but in cases like this,
there is no logical possibility of fall-through - or is there something I am
missing?


JSLint does not currently do the flow analysis to determine that every path
through a case returns. So move the break after case 1 to just before case 1.

Also, don't use a switch when there are only two cases. Use an if instead.
Perhaps JSLint should suggest that.

#1700 From: "biggeleben" <biggeleben@...>
Date: Thu Dec 30, 2010 1:05 pm
Subject: Re: Strict white space bug?
biggeleben
Send Email Send Email
 
--- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
>
>> [...]
>
> JSLint doesn't like silly indentation schemes.
> Turn off the Strict Whitespace option.
>

Ok, that's a pragmatic solution :) However, the "Strict Whitespace" option is
very helpful. Please think of tons of code and a bunch of developers of which
some always need a punch to remember code conventions. Turning off that option
reopens the door for messy code. Have you ever thought about splitting up this
particular option into "Strict Whitespace" and "Strict indentation"?

I just downloaded the JSLint code and played around a bit. The indentation check
relies on "option.white" as well. Patching that single if clause keeps "Strict
Whitespace" turned on without caring about indentation. That would be so great
as a permanent feature!

For complex JQuery chains, we still need those "silly" indentation schemes to
get readable code. I could patch the JSLint code to even work with silly
indentation (just an experiment). But afterwards, I recognized that strict
indentation might be not as important as using "inline white spaces" properly,
since developers tend to indent things right at least on the block level.

#1701 From: "Alex" <thespineproject@...>
Date: Thu Dec 30, 2010 9:02 pm
Subject: Using setTimout and setInterval
trueman_boy
Send Email Send Email
 
Hey guys,

I've had this silly bug with setTimeout today where I put this line of code:

setTimeout(getDatesOfWeek(), 1000);

So I reference the function and expect it to do it's thing every 1 second, but
it only did it 1 time.
From websites explaining the use of setTimeout and setInterval they all show
this:

setTimeout("getDatesOfWeek()", 1000);

So when JSLint pops an error for that line, saying it's evil or what ever, and
you should remove the "", I just removed them, but lost my functionality. Well,
actually, it didn't work as intended with the "" also, but that's another issue.

Question is, Since JSLint and FireBug console don't show an error on my original
line, how come putting a function (method?) call in setTimeout is valid code?
And if it's not, maybe JSLint should worn about it.

Thanks.

#1702 From: Mark Volkmann <r.mark.volkmann@...>
Date: Thu Dec 30, 2010 9:06 pm
Subject: Re: [jslint] Using setTimout and setInterval
mark_volkmann
Send Email Send Email
 
On Thu, Dec 30, 2010 at 3:02 PM, Alex <thespineproject@...> wrote:

>
>
> Hey guys,
>
> I've had this silly bug with setTimeout today where I put this line of
> code:
>
> setTimeout(getDatesOfWeek(), 1000);
>
> So I reference the function and expect it to do it's thing every 1 second,
> but it only did it 1 time.
> From websites explaining the use of setTimeout and setInterval they all
> show this:
>
> setTimeout("getDatesOfWeek()", 1000);
>
> So when JSLint pops an error for that line, saying it's evil or what ever,
> and you should remove the "", I just removed them, but lost my
> functionality. Well, actually, it didn't work as intended with the "" also,
> but that's another issue.
>
> Question is, Since JSLint and FireBug console don't show an error on my
> original line, how come putting a function (method?) call in setTimeout is
> valid code? And if it's not, maybe JSLint should worn about it.
>

Try this:

setTimeout(getDatesOfWeek, 1000);

Not that this passes the function getDatesOfWeek to setTimeout
rather than passing the result of invoking it.

--
R. Mark Volkmann
Object Computing, Inc.


[Non-text portions of this message have been removed]

#1703 From: "Alex" <thespineproject@...>
Date: Thu Dec 30, 2010 10:13 pm
Subject: Re: [jslint] Using setTimout and setInterval
trueman_boy
Send Email Send Email
 
Oops, I forgot to mention that was after I found the solution which is to remove
the ().

But the question still stand as for how come it's valid and doesn't pop an
error.

--- In jslint_com@yahoogroups.com, Mark Volkmann <r.mark.volkmann@...> wrote:
>
> On Thu, Dec 30, 2010 at 3:02 PM, Alex <thespineproject@...> wrote:
>
> >
> >
> > Hey guys,
> >
> > I've had this silly bug with setTimeout today where I put this line of
> > code:
> >
> > setTimeout(getDatesOfWeek(), 1000);
> >
> > So I reference the function and expect it to do it's thing every 1 second,
> > but it only did it 1 time.
> > From websites explaining the use of setTimeout and setInterval they all
> > show this:
> >
> > setTimeout("getDatesOfWeek()", 1000);
> >
> > So when JSLint pops an error for that line, saying it's evil or what ever,
> > and you should remove the "", I just removed them, but lost my
> > functionality. Well, actually, it didn't work as intended with the "" also,
> > but that's another issue.
> >
> > Question is, Since JSLint and FireBug console don't show an error on my
> > original line, how come putting a function (method?) call in setTimeout is
> > valid code? And if it's not, maybe JSLint should worn about it.
> >
>
> Try this:
>
> setTimeout(getDatesOfWeek, 1000);
>
> Not that this passes the function getDatesOfWeek to setTimeout
> rather than passing the result of invoking it.
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>
>
> [Non-text portions of this message have been removed]
>

#1704 From: Joshua Bell <josh@...>
Date: Thu Dec 30, 2010 10:44 pm
Subject: Re: [jslint] Using setTimout and setInterval
inexorabletash
Send Email Send Email
 
On Thu, Dec 30, 2010 at 2:13 PM, Alex <thespineproject@...> wrote:

> Oops, I forgot to mention that was after I found the solution which is to
> remove the ().
>
> But the question still stand as for how come it's valid and doesn't pop an
> error.
>

Consider:

function make_callback(arg) {
      console.log("making a new callback function...");
      var cb = function() {
          console.log("callback called: ", 123);
      };
      return cb;
}

Compare the difference in behavior between this:

>> setTimeout(make_callback, 1000);
<<one second passes>>
making a new callback function...

And this:

>> setTimeout(make_callback("blah"), 1000);
making a new callback function...
<<one second passes>>
callback called: blah

In the first case, you're passing a function reference setTimeout (to call
later). In the second case, you're evaluating a function and passing the
return value (hopefully a function reference) to setTimeout. Both are valid
use cases of setTimeout. In this example, passing the function reference
directly (the first case) is probably not what was intended since the newly
created callback function is simply discarded.

...

To stem the flow of questions of this sort to the JSLint group, would it
make sense to have each JSLint warning/ error include a hyperlink to a page
(which might be a Wiki document) with the collected wisdom of the group on
how to address the error? (Or possibly just a link to a particular part of
the http://www.jslint.com/lint.html page that details the error case and
describes how to disable the option (if necessary)?


[Non-text portions of this message have been removed]

#1705 From: Erik Eckhardt <erik@...>
Date: Thu Dec 30, 2010 11:08 pm
Subject: Re: [jslint] Using setTimout and setInterval
vorpalmage
Send Email Send Email
 
It's not an error because setTimeout expects a function as the first
parameter. However, if the first parameter is of type string, presumably it
wraps it in an anoymous function as in `new Function('invocation()');`

It is a solid and core concept of javascript that a function variable is
invoked with parentheses and is only referenced without them.

function returnafunction() {
___return function(a, b) {return a + b;};
}

function invokeafunction(fn) {
___fn();
}

x = returnafunction();
invokeafunction(x);

On Thu, Dec 30, 2010 at 2:13 PM, Alex <thespineproject@...> wrote:

>
>
> Oops, I forgot to mention that was after I found the solution which is to
> remove the ().
>
> But the question still stand as for how come it's valid and doesn't pop an
> error.
>
> --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>, Mark
> Volkmann <r.mark.volkmann@...> wrote:
>
> >
> > On Thu, Dec 30, 2010 at 3:02 PM, Alex <thespineproject@...> wrote:
> >
> > >
> > >
> > > Hey guys,
> > >
> > > I've had this silly bug with setTimeout today where I put this line of
> > > code:
> > >
> > > setTimeout(getDatesOfWeek(), 1000);
> > >
> > > So I reference the function and expect it to do it's thing every 1
> second,
> > > but it only did it 1 time.
> > > From websites explaining the use of setTimeout and setInterval they all
> > > show this:
> > >
> > > setTimeout("getDatesOfWeek()", 1000);
> > >
> > > So when JSLint pops an error for that line, saying it's evil or what
> ever,
> > > and you should remove the "", I just removed them, but lost my
> > > functionality. Well, actually, it didn't work as intended with the ""
> also,
> > > but that's another issue.
> > >
> > > Question is, Since JSLint and FireBug console don't show an error on my
> > > original line, how come putting a function (method?) call in setTimeout
> is
> > > valid code? And if it's not, maybe JSLint should worn about it.
> > >
> >
> > Try this:
> >
> > setTimeout(getDatesOfWeek, 1000);
> >
> > Not that this passes the function getDatesOfWeek to setTimeout
> > rather than passing the result of invoking it.
> >
> > --
> > R. Mark Volkmann
> > Object Computing, Inc.
> >
> >
> > [Non-text portions of this message have been removed]
> >
>
>
>


[Non-text portions of this message have been removed]

#1706 From: "Alex" <thespineproject@...>
Date: Fri Dec 31, 2010 1:41 am
Subject: Re: [jslint] Using setTimout and setInterval
trueman_boy
Send Email Send Email
 
Thanks for the thorough explanation, it seems more logical now.
But I still can't get my head around it...

Here's my test code:

function getDatesOfWeek() {
	 var currentDate = new Date(),
		 theTime = currentDate.getSeconds();
	 document.body.innerHTML = theTime;
	 setTimeout(getDatesOfWeek(), 1000);
}
getDatesOfWeek();

Which does not update the seconds. But if I remove the () or put
"getDatesOfWeek()", it does work. Which bugs me even more cause I understood
from what you wrote that if I put "" then it's just like invoking the
getDatesOfWeek(), which should give the same result?

If you can explain these 3 cases, I'll be set :-).

--- In jslint_com@yahoogroups.com, Joshua Bell <josh@...> wrote:
>
> On Thu, Dec 30, 2010 at 2:13 PM, Alex <thespineproject@...> wrote:
>
> > Oops, I forgot to mention that was after I found the solution which is to
> > remove the ().
> >
> > But the question still stand as for how come it's valid and doesn't pop an
> > error.
> >
>
> Consider:
>
> function make_callback(arg) {
>      console.log("making a new callback function...");
>      var cb = function() {
>          console.log("callback called: ", 123);
>      };
>      return cb;
> }
>
> Compare the difference in behavior between this:
>
> >> setTimeout(make_callback, 1000);
> <<one second passes>>
> making a new callback function...
>
> And this:
>
> >> setTimeout(make_callback("blah"), 1000);
> making a new callback function...
> <<one second passes>>
> callback called: blah
>
> In the first case, you're passing a function reference setTimeout (to call
> later). In the second case, you're evaluating a function and passing the
> return value (hopefully a function reference) to setTimeout. Both are valid
> use cases of setTimeout. In this example, passing the function reference
> directly (the first case) is probably not what was intended since the newly
> created callback function is simply discarded.
>
> ...
>
> To stem the flow of questions of this sort to the JSLint group, would it
> make sense to have each JSLint warning/ error include a hyperlink to a page
> (which might be a Wiki document) with the collected wisdom of the group on
> how to address the error? (Or possibly just a link to a particular part of
> the http://www.jslint.com/lint.html page that details the error case and
> describes how to disable the option (if necessary)?
>
>
> [Non-text portions of this message have been removed]
>

#1707 From: Mark Volkmann <r.mark.volkmann@...>
Date: Fri Dec 31, 2010 11:40 am
Subject: Re: [jslint] Using setTimout and setInterval
mark_volkmann
Send Email Send Email
 
I looks like you want to update the seconds every 1000 ms. I think you want
this:

function updateSeconds() {
   var currentDate = new Date();
   document.body.innerHTML = currentDate.getSeconds();
}

setInterval(updateSeconds, 1000);

On Thu, Dec 30, 2010 at 7:41 PM, Alex <thespineproject@...> wrote:

>
>
> Thanks for the thorough explanation, it seems more logical now.
> But I still can't get my head around it...
>
> Here's my test code:
>
> function getDatesOfWeek() {
> var currentDate = new Date(),
> theTime = currentDate.getSeconds();
> document.body.innerHTML = theTime;
> setTimeout(getDatesOfWeek(), 1000);
> }
> getDatesOfWeek();
>
> Which does not update the seconds. But if I remove the () or put
> "getDatesOfWeek()", it does work. Which bugs me even more cause I understood
> from what you wrote that if I put "" then it's just like invoking the
> getDatesOfWeek(), which should give the same result?
>
> If you can explain these 3 cases, I'll be set :-).
>
> --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>, Joshua
> Bell <josh@...> wrote:
> >
> > On Thu, Dec 30, 2010 at 2:13 PM, Alex <thespineproject@...> wrote:
> >
> > > Oops, I forgot to mention that was after I found the solution which is
> to
> > > remove the ().
> > >
> > > But the question still stand as for how come it's valid and doesn't pop
> an
> > > error.
> > >
> >
> > Consider:
> >
> > function make_callback(arg) {
> > console.log("making a new callback function...");
> > var cb = function() {
> > console.log("callback called: ", 123);
> > };
> > return cb;
> > }
> >
> > Compare the difference in behavior between this:
> >
> > >> setTimeout(make_callback, 1000);
> > <<one second passes>>
> > making a new callback function...
> >
> > And this:
> >
> > >> setTimeout(make_callback("blah"), 1000);
> > making a new callback function...
> > <<one second passes>>
> > callback called: blah
> >
> > In the first case, you're passing a function reference setTimeout (to
> call
> > later). In the second case, you're evaluating a function and passing the
> > return value (hopefully a function reference) to setTimeout. Both are
> valid
> > use cases of setTimeout. In this example, passing the function reference
> > directly (the first case) is probably not what was intended since the
> newly
> > created callback function is simply discarded.
> >
> > ...
> >
> > To stem the flow of questions of this sort to the JSLint group, would it
> > make sense to have each JSLint warning/ error include a hyperlink to a
> page
> > (which might be a Wiki document) with the collected wisdom of the group
> on
> > how to address the error? (Or possibly just a link to a particular part
> of
> > the http://www.jslint.com/lint.html page that details the error case and
> > describes how to disable the option (if necessary)?
> >
> >
> > [Non-text portions of this message have been removed]
> >
>
>
>



--
R. Mark Volkmann
Object Computing, Inc.


[Non-text portions of this message have been removed]

#1708 From: "Cheney, Edward A SSG RES USAR USARC" <austin.cheney@...>
Date: Fri Dec 31, 2010 2:18 pm
Subject: Re: [jslint] Re: Strict white space bug? (UNCLASSIFIED)
sandyhead25
Send Email Send Email
 
Classification: UNCLASSIFIED

> Ok, that's a pragmatic solution :)  However, the "Strict Whitespace"
> option is very helpful.  Please think of tons of code and a bunch of
> developers of which some always need a punch to remember code
> conventions.  Turning off that option reopens the door for messy code.
> Have you ever thought about splitting up this particular option into
> "Strict Whitespace" and "Strict indentation"?

Instead of altering some validation software to conform to user behavior
perhaps you should alter your process to mitigate differences in user
behavior and the validation software.  You need an automated beautifier
that conforms to JSLint's white space rules.  I recommend one of the two
following.  The beautification algorithm in the second is an early fork
of the first and is similar but very different.

http://jsbeautifier.org/
http://prettydiff.com/

Austin Cheney, CISSP
Classification: UNCLASSIFIED

#1709 From: "Felix E. Klee" <felix.klee@...>
Date: Fri Dec 31, 2010 5:33 pm
Subject: Circular Function Definitions
feklee
Send Email Send Email
 
If I write code such as the following, then JSLint complains that "f" is
not defined.

   var sendToServer;

   function callback(moreToDo) {
     // do something ...
     if (moreToDo) {
       f();
     }
   }

   function f() {
     sendToServer('xyz', callback);
   }

What's the most elegant solution to get rid of the error message?

What I currently do, and what I consider inconsistent, and thus
confusing:

   var sendToServer,
   f; // to get rid of JSLint error message

   function callback(moreToDo) {
     // do something ...
     if (moreToDo) {
       f();
     }
   }

   f = function () {
     sendToServer('xyz', callback);
   };

#1710 From: Erik Eckhardt <erik@...>
Date: Fri Dec 31, 2010 6:21 pm
Subject: Re: [jslint] Circular Function Definitions
vorpalmage
Send Email Send Email
 
Instead of passing in a flag and then hardcoding the function, pass in a
function:

function callback(morefn) {
___// do something ...
___if (typeof(morefn) === 'function') {
______moref();
___}
}

f = function () {
___sendToServer('xyz', callback ? f : null);
};

You could alternately make f take a parameter that when false causes an
immediate return. When true or missing, nothing happens. Then:

___sendToServer('xyz', function() {f(callback)});

>


[Non-text portions of this message have been removed]

#1711 From: "Felix E. Klee" <felix.klee@...>
Date: Fri Dec 31, 2010 8:12 pm
Subject: Re: [jslint] Circular Function Definitions
feklee
Send Email Send Email
 
On Fri, Dec 31, 2010 at 7:21 PM, Erik Eckhardt <erik@...> wrote:
> function callback(morefn) {
>     // do something ...
>     if (typeof(morefn) === 'function') {
>         moref();
>     }
> }
>
> f = function () {
>     sendToServer('xyz', callback ? f : null);
> };

Are you sure this makes sense? The second last line will always evaluate to:

   sendToServer('xyz', f);

And I don't see how this solves the issue I raised:

   var f;

   function callback(moreToDo) {
       // ...
   }

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

That's inconsistent, and thus confusing. Of course one could write:

   var callback, f;

   callback = function (moreToDo) {
       // ...
   };

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

Now things are consistent. But is that the way to go?

#1712 From: "Rob Richardson" <erobrich@...>
Date: Fri Dec 31, 2010 8:49 pm
Subject: RE: [jslint] Circular Function Definitions
erobrich@...
Send Email Send Email
 
Felix,

The primary concern is you're trying to use a function earlier in your code
file than when it is defined.  If you put var f = function () {... before
function callback(... then JSLint would likely be fine.  I understand that
given the business rules around the code in question that callback() (and
thus f()) would never be used before it was defined, but JSLint doesn't know
that.

The secondary concern is that you're passing in a flag that says whether you
should use a follow-up function.  Perhaps you refactored f() out of
callback() for readability, perhaps f() is used in more than one place,
perhaps you never considered putting the contents of f inside callback.
Alas, the "moreToDo is true means run f()" is a bit confusing.  Passing the
function to run into callback() instead of a flag makes callback() more
generic, and makes this point a bit more clear, and that was the focus of
Erik's thoughts.

Rob


-----Original Message-----
From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On
Behalf Of Felix E. Klee
Sent: Friday, December 31, 2010 1:12 PM
To: jslint_com@yahoogroups.com
Subject: Re: [jslint] Circular Function Definitions

On Fri, Dec 31, 2010 at 7:21 PM, Erik Eckhardt <erik@...> wrote:
> function callback(morefn) {
>     // do something ...
>     if (typeof(morefn) === 'function') {
>         moref();
>     }
> }
>
> f = function () {
>     sendToServer('xyz', callback ? f : null);
> };

Are you sure this makes sense? The second last line will always evaluate to:

   sendToServer('xyz', f);

And I don't see how this solves the issue I raised:

   var f;

   function callback(moreToDo) {
       // ...
   }

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

That's inconsistent, and thus confusing. Of course one could write:

   var callback, f;

   callback = function (moreToDo) {
       // ...
   };

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

Now things are consistent. But is that the way to go?

Messages 1683 - 1712 of 3202   Oldest  |  < Older  |  Newer >  |  Newest
Add to My Yahoo!      XML What's This?

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help