Javascript class pattern to satify JSHhint (on cloud9)?

33 views Asked by At

I'm creating Javascript classes using cloud9 but JSHint is complaining of unused locals - how do I correctly do what I want? A minimal example is this:

/* jshint unused: false */
function Test(dummy) {
    var _dummy = dummy;
}

Test.prototype.interface = function() {
    this._dummy = 23;
};

I get '_dummy' is defined by never used. from JSHint running in the cloud9 editor. I'm also puzzled by the jshint directive not working and the this._dummy = 23; apparently being OK. Thanks for suggestions of further reading for me - still getting my head around Javascript ;-). I have 'Javascript The Definitive Guide, 6th Edition' to hand in case there's somethig that I've misread in there.

1

There are 1 answers

0
T.J. Crowder On BEST ANSWER

Your var _dummy = dummy; line creates a local variable called _dummy inside the constructor, which you assign the parameter's value to but then never use.

You probably meant to store it as a property:

function Test(dummy) {
    this._dummy = dummy;
//  ^^^^^
}