Published 4/9/2016 ยท 1 min read
Tags: javascript
Factory Function To Create An Object In JavaScript
Use a constructor function that returns an object. You can then create multiple people passing in the first and last name arguments the createPerson function.
var createPerson = function(firstName, lastName) {
return {
firstName: firstName,
lastName: lastName,
sayHi: function() {
return "Hi there";
}
};
var johnDoe = createPerson("John", "Doe");
var janeDoe = createPerson("Jane", "Doe"); Related Articles
- Kotlin for JS/TS Developers
A practical guide to Kotlin for JavaScript and TypeScript developers, covering lambdas, null safety, classes, coroutines, and common gotchas.
- Testing Svelte 5 Apps: A Practical Guide to Code Structure
How to structure your Svelte code so it's actually testable, with real examples from building a wallet auth system.
- Compressed NFTs: Collections, Verification, and Building a Claim Page
Taking our cNFT minting system to production: creating verified collections, building a web-based claim flow, and preparing for mainnet deployment.