Created
September 30, 2015 15:18
-
-
Save spikesagal/82266092e8f7b2540937 to your computer and use it in GitHub Desktop.
Self-incrementing, read-only counter property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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