-
-
Save joepie91/657f2b4b054d90aa0c87 to your computer and use it in GitHub Desktop.
Object factory (without prototype) in JavaScript
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
function createUser(name, height, properties) { | |
return Object.assign({ | |
name: name, | |
height: height, | |
noise: "hello world!", | |
makeNoise: function() { | |
console.log(this.noise); | |
} | |
}, properties); | |
} | |
var user = createUser("joepie91", "1.94m", { | |
noise: "hallo!" | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment