Skip to content

Instantly share code, notes, and snippets.

@spikesagal
Created September 30, 2015 22:05
Show Gist options
  • Save spikesagal/e4c0ed40592b2d76abbd to your computer and use it in GitHub Desktop.
Save spikesagal/e4c0ed40592b2d76abbd to your computer and use it in GitHub Desktop.
Self-incrementing, read-only counter property; prototype linking version.
(function IIFE() {
'use strict';
function counter() {
this.def = 0;
return (function() {
return this.def++;
}).bind(this);
};
var obj = {};
Object.defineProperties(obj, {
counter: {
get: new counter,
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