Skip to content

Instantly share code, notes, and snippets.

@spikesagal
Created September 30, 2015 15:18
Show Gist options
  • Save spikesagal/82266092e8f7b2540937 to your computer and use it in GitHub Desktop.
Save spikesagal/82266092e8f7b2540937 to your computer and use it in GitHub Desktop.
Self-incrementing, read-only counter property
(function IIFE() {
'use strict';
var obj = {};
Object.defineProperties(obj, {
counter: {
get: (function IIFE() {
var def = 0;
return function() {
return def++;
}
})(),
enumerable: true
}
});
console.log(obj.counter, obj.counter, obj.counter);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment