Skip to content

Instantly share code, notes, and snippets.

@oropesa
Last active November 6, 2019 12:16
Show Gist options
  • Save oropesa/d49189174b067e6dcd15f8c47729c77b to your computer and use it in GitHub Desktop.
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.
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