Last active
November 6, 2019 12:16
-
-
Save oropesa/d49189174b067e6dcd15f8c47729c77b to your computer and use it in GitHub Desktop.
Object with private property. Object with function property. Object with function property without parenthesis.
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
var example = ( function() { | |
var private = 0; | |
var fnIncrement = function() { | |
return ++private; | |
} | |
var returned = { fnIncrement: fnIncrement }; | |
Object.defineProperty( returned, 'autoIncrement', { get: fnIncrement } ); | |
return returned; | |
} )(); | |
example.fnIncrement() // 1 | |
example.autoIncrement // 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment