0

Here is my code:

var A = (function(){
    "use strict";

    function FetchJSON(){
        return someValue;
    }

    var Class = function(){
        // how do I correctly call FetchJSON() from inside this class definition?
    };

    return {
        Class: Class,
        fetchJson: FetchJSON
    };
})()

So basically I'm using JSLint to clean up my code and I'm just calling FetchJSON() from inside the Class object/function definition but JSLint is telling me I need to use the word 'new' before the FetchJSON() call and I'm thinking I don't. The code works with out the word 'new' just fine but JSLint is telling me it should have it. What's the deal?

Thanks

Ryan
  • 6,756
  • 13
  • 49
  • 68
  • 4
    It's probably because the first letter of `FetchJSON` is capitalized and JSLint thinks it's a constructor. – David G Sep 05 '12 at 13:39

3 Answers3

1

Call the function fetchJSON instead of FetchJSON, so JSLint does not think it's a constructor.

gpvos
  • 2,722
  • 1
  • 17
  • 22
1

By convention only functions that are intended to be used as constructors (ie with the new keyword) should begin with capital letters - see this question for more detail.

Community
  • 1
  • 1
codebox
  • 19,927
  • 9
  • 63
  • 81
1

It's because the first letter of FetchJSON is capitalized, causing JSLint to interpret it as a constructor. If you wish to keep it capitalized despite the warning, you may.

David G
  • 94,763
  • 41
  • 167
  • 253