-2

So I have been developing a modal control for several months. It is custom coded to my clients needs but I want to release it to the generic public. I have been working to get it to minify via codekit as well as uglify.

Here is an example of the remaining warnings I am receiving.

How can I best remove theses warnings? I extended the typeof function in order to know the variations between objects and arrays.

var com = {
 load: function(template, $el, obj, append, callback){
  $.get(template, function(value){
   $.templates("tmpl", value);
   var html = $.render.tmpl(obj);
   if(append){ $el.append(html); }else{ $el.html(html); }
  }).done(function(){
   if(callback !== undefined && com.type(callback) === "function"){ callback(); }
  });
 },
 checkApiEvents: function(api){
  if(!$.isEmptyObject(api.doc)){ $.each(api.doc, function(k,v){ if(com.type(v) === "function"){ $.e.doc[k].push(v); } }); }
  if(!$.isEmptyObject(api.win)){ $.each(api.win, function(k,v){ if(com.type(v) === "function"){ $.e.win[k].push(v); } }); }
 },
 type: function(name){
  switch(name){
   case "function": return "function"; break;
   case "object": if($.isArray(name)){return "array"; }else{ return "object"; } break;
   case "string": return "string"; break;
   case "number": if(!isNaN(name)){ return "number"; }else{ return "string"; } break;
   case '': case "undefined": default: return "undefined"; break;
  }
 },
};

enter image description here

googabeast
  • 172
  • 9
  • 4
    Don't break after you return. Nothing executes after a return. A return is enough, the break is unreachable and unnecessary. Get rid of it. – Andrew Li Jul 01 '17 at 02:38
  • Thanks Andrew, after adding a break brefore the default it cleared all the remaining warnings, – googabeast Jul 02 '17 at 00:52
  • If it's actually about making the warnings not show up (i.e. you're temporarily using an early return to test something), you can specify `/* jshint -W027 */`. Not recommended for production, of course – Ben Philipp Nov 12 '20 at 12:36

3 Answers3

1

If you find this question looking for the error in jshint W027 - Unreachable '$' after 'return' and want to return early (for now) then an easy solution to make the jshint warning go away is to use a conditional:

function doThis(){
    if (1) return true;
    // I want to keep this but return early for now
    myVar = 0;
}
ow3n
  • 5,974
  • 4
  • 53
  • 51
0

You need a break to break off a loop or switch not going further down the body of the block(loop/switch). The return breaks off from the function itself. So once a return is called there no point of any statement after a return.

Rajeev Ranjan
  • 3,588
  • 6
  • 28
  • 52
-1

A return statement "exits" the function immediately so any code after it will never be run.

function hello() {
    console.log('this will run');
    return;
    console.log('this will never run');
}

Yes, you can put return statements inside if blocks, but if they're called, nothing after that return statement, or outside the if block will be run either.

function hello() {
    console.log('this will run');

    var x = true;

    if (x === true) {
        console.log('this will run');
        return;
        console.log('this will never run');
    }
    else {
        return; // this will never return
    }

    console.log('this will only run if x is false');
}
Soviut
  • 88,194
  • 49
  • 192
  • 260