Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSLint Expected 'set' and instead saw ''

JS Linting the following bit of code:

/*jslint 
browser: true,
es5: true,
*/

var VCA = {
    get enable () {
        'use strict';
        return 0;
    },
    set enable (value) {
        'use strict';
        console.log(value);
    }
};

Results in the error:

Problem at line 11 character 9: Expected 'set' and instead saw ''.

set enable (value) {

I don't understand what to do to make this see 'set' correctly?!

I know about the __defineGetter__ syntax but really want to use the above style.

Does anyone have more information on this error?

like image 228
Matt Clarkson Avatar asked Sep 06 '11 15:09

Matt Clarkson


1 Answers

It seems to be a problem in JSLint. I can't get any get/set scenario to validate in JSLint. Your syntax seems to be right, and in line with Douglas' initial post about getter setter validation.


edit: this validates fine, so might be a workaround :-)

var myObject = {};

(function () {
    var myProp = 'myDefault';
    Object.defineProperty(myObject, 'myProp', 
        {
            enumerable:     false,
            configurable:   true,
            get: function () {
                return myProp;
            },
            set: function (value) {
                myProp = value + ' lala';
            }
        });
}());
like image 191
Jan Jongboom Avatar answered Sep 21 '22 10:09

Jan Jongboom