Skip to content

Instantly share code, notes, and snippets.

/user.js Secret

Created May 24, 2016 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/68695ffc6d92e0af52751ed47bd2c941 to your computer and use it in GitHub Desktop.
Save anonymous/68695ffc6d92e0af52751ed47bd2c941 to your computer and use it in GitHub Desktop.
javascript up. public methods
var User = (function() { // IIFE mit Closure
var _firstname;
var _lastname;
function User(firstname, lastname) {
_firstname = firstname;
_lastname = lastname;
}
User.prototype.getFullName = function() {
return _lastname + ', ' + _firstname;
}
return User;
})();
// Beispiel
var user = new User('Max', 'Mustermann');
user._firstname = 'Peter'; // Hat keine Auswirkungen...
console.log(user.getFullName()); // Mustermann, Max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment