Answer the question
In order to leave comments, you need to log in
Why is this pattern code in PHPStorm highlighted as erroneous and not working?
var module = (function () {
var counter = 0,
module = {};
module.incrementCounter: function() {
return ++counter;
}
module.resetCounter: function () {
return counter = 0;
}
module.getCounter:function () {
return counter;
}
return module;
})();
Answer the question
In order to leave comments, you need to log in
Because you mixed the syntax for enumerating object properties and assigning values to object properties.
Either way
var module = (function () {
var counter = 0;
return {
incrementCounter: function() {
return ++counter;
},
resetCounter: function () {
return counter = 0;
},
getCounter:function () {
return counter;
}
};
})();
var module = (function () {
var counter = 0,
module = {};
module.incrementCounter = function() {
return ++counter;
};
module.resetCounter = function () {
return counter = 0;
};
module.getCounter = function () {
return counter;
};
return module;
})();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question