How to promote MDN over W3Schools?

160 views
Skip to first unread message

AJ ONeal

unread,
Jan 24, 2012, 2:31:48 PM1/24/12
to node.js mailing list, UtahJS
Every time I see `setTimeout("doSomething()", 1000);` instead of `setTimeout(doSomething, 1000);` I shed a tear (or maybe two or three, especially if the entire function is in quotes rather than just the name).

I won't link to the example, but it's there, on that site. 

I was thinking that maybe we can all 
  1. visit google.com
  2. search for "JavaScript Arrays"
  3. find the 5 entry down or so that is from MDN and click the plus 1
  4. find the 1st entry or so from W3Schools and click on it
  5. once the page loads, click back
  6. click the "block all results from w3schools.com" button
Maybe if enough people do that the learning algorithm will start to put the correct results at the top of the page.

And of course, there's the old fashioned way:
Senselessly linking every JavaScript-related term to developer.mozilla.org on every article, presentation, and podcast transcript we're part of.


Any other ideas?

AJ ONeal

AJ ONeal

unread,
Jan 24, 2012, 2:32:36 PM1/24/12
to node.js mailing list, UtahJS
dangit... ugh... I accidentally linked to it anyway... epic fail

AJ ONeal

AJ ONeal

unread,
Jan 24, 2012, 2:35:58 PM1/24/12
to node.js mailing list, UtahJS
And here's the direct link to block the site from google results:


For reason for blocking I put "incorrect content, poor examples, anti-patterns"

AJ ONeal

Charles Wood

unread,
Jan 24, 2012, 2:41:54 PM1/24/12
to uta...@googlegroups.com, node.js mailing list
setInterval("findAjsHeart().ripItOut()", everyTimeSomeoneUsesAString());

--
Lunches rotate between cities every Wednesday.
Lindon: first Thursday of every month: http://utahjs.com/meetings/
 
----
Unsubscribe: utahjs+un...@googlegroups.com
Options: http://groups.google.com/group/utahjs

Ken Snyder

unread,
Jan 24, 2012, 3:35:20 PM1/24/12
to uta...@googlegroups.com, node.js mailing list
Sweet. Is it just me or does the +1 button not appear on Safari for OSX Lion?

- Ken


On Tue, Jan 24, 2012 at 12:31 PM, AJ ONeal <cool...@gmail.com> wrote:

AJ ONeal

Ryan Corradini

unread,
Jan 25, 2012, 9:06:33 AM1/25/12
to Utah JavaScript
> Sweet. Is it just me or does the +1 button not appear on Safari for OSX
> Lion?

FWIW, I'm pretty sure you need to be signed in to a Google account to
see the +1 buttons.

As for promotion of MDN over W3, Chris Williams of JSConf fame has an
initiative he calls "Promote JS" (promotejs.com) that gives you the
tools to easily implement the "post links to JS terms" method AJ
mentions in the original post. Above and beyond that, w3fools.com is
worth a read; it covers the how & why of this whole situation pretty
well.

Brad Midgley

unread,
Jan 25, 2012, 10:53:23 AM1/25/12
to uta...@googlegroups.com
I still get w3schools results after adding "w3schools.com" to the
google block list. hrmph.

AJ ONeal

unread,
Jan 25, 2012, 11:39:07 AM1/25/12
to uta...@googlegroups.com
try blocking it with the leading 'www.'

AJ ONeal

On Wed, Jan 25, 2012 at 8:53 AM, Brad Midgley <bmid...@gmail.com> wrote:
I still get w3schools results after adding "w3schools.com" to the
google block list. hrmph.

Michael Jones

unread,
Jan 25, 2012, 11:52:15 AM1/25/12
to uta...@googlegroups.com, node.js mailing list
On your setTimeout complaint…. FWIW, the MDN examples on setTimeout also include using a string:

window.setTimeout('window.parent.generateOutput()', 1000);  

And honestly, I've often used the syntax if passing parameters into the function, as IE at least does not (or did not) support passing additional parameters into setTimeout to have those passed on to the function. I do realize the point that MDN makes about this functionality being similar to an eval(), but there are some legitimate uses for it, particularly if you have a function in which you need to pass parameters into that may not have anything to do with user input. If recent versions of IE have added support for passed parameters then that's great, but otherwise I'm not aware of any alternative.

--

No trees were knowingly harmed in any way during the production and transmission of this message. However, a rather large number of electrons were somewhat inconvenienced.

Kirk Cerny

unread,
Jan 25, 2012, 12:07:22 PM1/25/12
to uta...@googlegroups.com, node.js mailing list
I typically wrap the call in a closure to attempt to solve this.
I wrote this fast from memory, so there might be issues.
But this is the idea.

var callLater = function (functionObject, timeout, paramArray)
{
    var proxyFunction = function ()
    {
        functionObject.apply(window, paramArray);
    };
    window.setTimeout(proxyFunctiontimeout); 
};
callLater(window.parent.generateOutput, 1000, ["param1": "kirk"]);

AJ ONeal

unread,
Jan 25, 2012, 12:44:54 PM1/25/12
to uta...@googlegroups.com

I take it back.

Firebug and web inspector are (the only) legitimate use cases for evil.

Sent from my Android

On Jan 25, 2012 10:40 AM, "AJ ONeal" <cool...@gmail.com> wrote:

Yeah, I just create a named function and pass in the name.

I don't believe in legitimate uses of eval or its cousins.

Sent from my Android

AJ ONeal

unread,
Jan 25, 2012, 12:45:57 PM1/25/12
to uta...@googlegroups.com

How cute. My phone knows correct auto substitution for the eval keyword.

Sent from my Android

Jamund Ferguson

unread,
Jan 25, 2012, 1:05:25 PM1/25/12
to uta...@googlegroups.com
I think @Substack uses eval in DNode to enable RPC craziness https://github.com/substack/dnode, which is used in www.browserling.com, a really cool site.

But for JSON parsing (and most things), it's unnecessary.

J

Ken Snyder

unread,
Jan 25, 2012, 1:17:23 PM1/25/12
to uta...@googlegroups.com
I agree that eval should not be used unless needed, but I think there are a fair number of good uses.

Most JS libraries provide an easy way eval javascript that is returned in script tags in an ajax response. Here is jQuery's that can be called manually or is called automatically with certain jQuery.ajax options: jQuery.globalEval.

Some selector libraries like NWMatcher use eval() or new Function("...") to compile selector logic. 

Here is a good discussion: Why eval can be bad

- Ken

Michael Jones

unread,
Jan 25, 2012, 1:27:48 PM1/25/12
to uta...@googlegroups.com
Agreed. The main problem with things like eval() (which keeps getting autocorrected to veal() on my end, heh) is when you do something stupid™ with it, such as taking user input and passing it into eval'ed code. But if you can control what goes into the string it's not so bad.

Either way, however, the issue still remains how do you pass an argument to a function called by setTimeout on IE if it doesn't support passing the params in separately? The string eval seems to be the only way.

--

No trees were knowingly harmed in any way during the production and transmission of this message. However, a rather large number of electrons were somewhat inconvenienced.

AJ ONeal

unread,
Jan 25, 2012, 12:40:33 PM1/25/12
to uta...@googlegroups.com

Yeah, I just create a named function and pass in the name.

I don't believe in legitimate uses of eval or its cousins.

Sent from my Android

On Jan 25, 2012 10:07 AM, "Kirk Cerny" <kirks...@gmail.com> wrote:

Ken Snyder

unread,
Jan 25, 2012, 1:30:25 PM1/25/12
to uta...@googlegroups.com
// To pass params, use an anonymous function (best used on all browsers)
window.setTimeout(function() {
  myFunc(param1, param2);
}, ms);

Michael Jones

unread,
Jan 25, 2012, 1:37:47 PM1/25/12
to uta...@googlegroups.com
OK, I have used that before as well, but wasn't sure that IE supported it either. On the bright side, at least IE is getting slightly better.

--

No trees were knowingly harmed in any way during the production and transmission of this message. However, a rather large number of electrons were somewhat inconvenienced.

Ryan Corradini

unread,
Jan 25, 2012, 1:54:59 PM1/25/12
to Utah JavaScript
The only problem with the anonymous function solution is one of scope.
This just bit me yesterday:

function processArray(arr) {
var i=0, len = arr.length;
for (i; i<len; i++) {
window.setTimeout(function() {
doSomething(arr[i]);
}, 500);
}
}

Looks like it should work, but every time doSomething gets called, the
parameter it receives is the final element in the array -- by the time
of the first invocation, i has already fallen out of the for loop and
been incremented to arr.length.

But you can rewrite this to make it work:

function processArray(arr) {
if (arr.length) {
window.setTimeout(function() {
doSomething(arr.shift());
processArray(arr); // warning, recursion alert!
}, 100);
}
}

This is just a hastily-hacked-together function; in real production
code you'd want to do something that didn't remove every item from the
array. ;)


On Jan 25, 1:30 pm, Ken Snyder <kendsny...@gmail.com> wrote:
> // To pass params, use an anonymous function (best used on all browsers)
> window.setTimeout(function() {
>   myFunc(param1, param2);
>
> }, ms);
>
> On Wed, Jan 25, 2012 at 11:27 AM, Michael Jones <jmichaeljo...@gmail.com>wrote:
>
>
>
> > Agreed. The main problem with things like eval() (which keeps getting
> > autocorrected to veal() on my end, heh) is when you do something stupid™
> > with it, such as taking user input and passing it into eval'ed code. But if
> > you can control what goes into the string it's not so bad.
>
> > Either way, however, the issue still remains how do you pass an argument
> > to a function called by setTimeout on IE if it doesn't support passing the
> > params in separately? The string eval seems to be the only way.
>
> > --
>
> > No trees were knowingly harmed in any way during the production and
> > transmission of this message. However, a rather large number of electrons
> > were somewhat inconvenienced.
>
> > On Wednesday, January 25, 2012 at 11:17 AM, Ken Snyder wrote:
>
> > I agree that eval should not be used unless needed, but I think there are
> > a fair number of good uses.
>
> > Most JS libraries provide an easy way eval javascript that is returned in
> > script tags in an ajax response. Here is jQuery's that can be called
> > manually or is called automatically with certain jQuery.ajax options:
> > jQuery.globalEval <http://api.jquery.com/jQuery.globalEval/>.
>
> > Some selector libraries like NWMatcher use eval() or new Function("...")
> > to compile selector logic.
>
> > Here is a good discussion: Why eval can be bad<http://stackoverflow.com/questions/86513/why-is-using-javascript-eval...>
>
> > - Ken
>
> > On Wed, Jan 25, 2012 at 10:44 AM, AJ ONeal <coola...@gmail.com> wrote:
>
> > I take it back.
>
> > Firebug and web inspector are (the only) legitimate use cases for evil.
>
> >  --
> > Lunches rotate between cities every Wednesday.
> > Lindon: first Thursday of every month:http://utahjs.com/meetings/
>
> > ----
> > Unsubscribe: utahjs+un...@googlegroups.com
> > Options:http://groups.google.com/group/utahjs
>
> >  --
> > Lunches rotate between cities every Wednesday.
> > Lindon: first Thursday of every month:http://utahjs.com/meetings/
>
> > ----
> > Unsubscribe: utahjs+un...@googlegroups.com
> > Options:http://groups.google.com/group/utahjs- Hide quoted text -
>
> - Show quoted text -

AJ ONeal

unread,
Jan 25, 2012, 2:03:28 PM1/25/12
to uta...@googlegroups.com
If you have a truly asynchronous loop, you should use something like forEachAsync

However, in your case all you need to do is to move your function out of the loop

    function createDoSomething(item) {
      return function () {
          doSomething(item);
      };
    }

    function processArray(arr) {
     var i=0, len = arr.length;
     for (i; i < len; i +=1 ) {
       window.setTimeout(createDoSomething(arr[i]), 500);
      }
    }

Generally, you should always pull your functions to the highest scope possible.

Only nest scopes if you're emulating class, subclass functionality or if it otherwise makes sense.

As a general rule, that will keep you out of trouble.

Also, use `forEach` instead of `for (i = 0; i < len; i += 1)` unless you find that there's a good reason to do it that way.

      function processArray(item, i) {
        function doSomethingBetter() {
          doSomething(item);
        };
        window.setTimeout(doSomethingBetter, 500);
      }
      arr.forEach(processArray);

AJ ONeal

Kyle Mathews

unread,
Jan 25, 2012, 2:13:26 PM1/25/12
to uta...@googlegroups.com
Underscore.js has a nice function that let's you pass in additional arguments:

_.delay = function(func, wait) {
    var args = slice.call(arguments, 2);
    return setTimeout(function(){ return func.apply(func, args); }, wait);
  };

--
Kyle Mathews

Blog: kyle.mathews2000.com/blog
Twitter: http://twitter.com/kylemathews



Ryan Corradini

unread,
Jan 25, 2012, 2:16:37 PM1/25/12
to Utah JavaScript
Cool repo, especially for Node-based code. For browser-side, though, I
tend to avoid forEach out of personal preference. IE<9 doesn't support
it natively, and the syntactic sugar isn't enough for me to justify
the need for a polyfill, no matter how small. If my current job
situation has taught me nothing else, it's that IE8 support still
matters. -_-


On Jan 25, 2:03 pm, AJ ONeal <coola...@gmail.com> wrote:
> If you have a truly asynchronous loop, you should use something like
> forEachAsynchttps://github.com/coolaj86/futures
>
> However, in your case all you need to do is to move your function out of
> the loop
>
>     function createDoSomething(item) {
>       return function () {
>           doSomething(item);
>       };
>     }
>
>     function processArray(arr) {
>      var i=0, len = arr.length;
>      for (i; i < len; i +=1 ) {
>        window.setTimeout(createDoSomething(arr[i]), 500);
>       }
>     }
>
> Generally, you should always pull your functions to the highest scope
> possible.
>
> Only nest scopes if you're emulating class, subclass functionality or if it
> otherwise makes sense.
>
> As a general rule, that will keep you out of trouble.
>
> Also, use `forEach` instead of `for (i = 0; i < len; i += 1)` unless you
> find that there's a good reason to do it that way.
>
>       function processArray(item, i) {
>         function doSomethingBetter() {
>           doSomething(item);
>         };
>         window.setTimeout(doSomethingBetter, 500);
>       }
>       arr.forEach(processArray);
>
> AJ ONeal
>
> > > > Options:http://groups.google.com/group/utahjs-Hide quoted text -

nodokodo

unread,
Jan 25, 2012, 9:44:29 AM1/25/12
to nod...@googlegroups.com, UtahJS
You want to block at least www.w3schools.com + wwww.w3schools.com + wap.w3schools.com; I don't know what other sub-domains they use but I've had these so far (lame block avoidance technique on the wwww?), wildcarding doesn't appear to work.

Graham Ballantyne

unread,
Jan 25, 2012, 12:02:30 AM1/25/12
to nod...@googlegroups.com, UtahJS
Reply all
Reply to author
Forward
0 new messages