Created
September 30, 2015 22:05
-
-
Save spikesagal/e4c0ed40592b2d76abbd to your computer and use it in GitHub Desktop.
Self-incrementing, read-only counter property; prototype linking version.
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'; | |
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