Template talk:Editnotices/Namespace/MediaWiki

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

JSHint[edit]

seems to be seriuously buggy:

if (foo) var bar = 'text'
else var bar = 'nontext'

bar.toUpperCase // Throws "bar used out of scope."


if (typeof(DelReqHandler) == 'undefined') //throws DelReqHandler not defined.

--DieBuche (talk) 10:16, 24 February 2011 (UTC)[reply]

Well, given that you define bar in an if-statement I think it's a valid error. For future development I think it's important to not assume something was defined in an if-statement. Instead define the variable's scope before the statement and overwrite as needed. And typeof() throws an error because typeof() is not a function! And if it would be, passing it an undefined variable throws an error (Yes in most browsers typeof can be used in a function-like way, but it's not a function)
var bar = 'nontext';
if (foo) {
  bar = 'text';
}

bar.toUpperCase();


if ( typeof DelReqHandler == 'undefined')
  alert(foo);
No errors there. –Krinkletalk 16:58, 12 March 2011 (UTC)[reply]
Sorry, I didn't see this thread until after I made this edit. –Krinkletalk 17:07, 12 March 2011 (UTC)[reply]