Last active
August 29, 2015 14:11
JS prototype with immediatly called function
This file contains hidden or 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
// 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