开发者

What does JSLint's "Bad Escapement" mean in this case?

I thougth "bad escapement" stands for wrong use escaping with slash.

Why does JSLint bring up the message in this function on the 3d line (for...)?

  function splitTags(commaSeparated) {
    var tagArray = commaSeparated.split(','); 
    for (var i=(tagArray.length) - 1; i>=0; i = i - 1 ){
      tagArray[i] = f.trim(tagArray[i]);
    }    
    return tagArray;
  }
  f.splitTags=splitTags;

Edit: I changed the "i--" to "i=i-1" and posted the changed version above.

Lint complains at character 30, which is the first minus sign.

Edit2: After this change it does not complain anymore. New version that works:

  fun开发者_StackOverflow社区ction splitTags(commaSeparated) {
    var tagArray = commaSeparated.split(',');
    var startWith = tagArray.length - 1; 
    for (var i=startWith; i>=0; i = i - 1 ){
      tagArray[i] = f.trim(tagArray[i]);
    }    
    return tagArray;
  }
  f.splitTags=splitTags;

Strange. I am actually using JSLint multi: http://ajaxian.com/archives/jslint-multi

So this is not solved but I have a workaround. But would be nice to get the real answer, I still have many of such code parts.


From the JSLint page:

JSLint expects that + will not be followed by + or ++, and that - will not be followed by - or --. A misplaced space can turn + + into ++, an error that is difficult to see. Use parens to avoid confusion..


I guess from the workaround that I posted in the Edit of the question that JSLint multi does not like the length keyword in the for line at all.

Do not use length there but calculate it in the line before and use a variable.

A rule to make JSLint multi not complain.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜