Skip to content

Instantly share code, notes, and snippets.

@der-On
Last active August 29, 2015 14:11
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 der-On/709dcdcf73ba5a1d40e0 to your computer and use it in GitHub Desktop.
Save der-On/709dcdcf73ba5a1d40e0 to your computer and use it in GitHub Desktop.
JS prototype with immediatly called function
// define constructor
function User() {
}
// define prototype using "this"
User.prototype = new (function() {
this.name = 'new User';
var pass = 'secret'
this.login = function() { ... }
this.logout = function() { ... }
})();
// define prototype without "this"
User.prototype = (function() {
var name = 'new User';
var pass = 'secret'
function login() { ... }
function logout() { ... }
return {
login: login,
logout: logout,
name: name
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment