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
- 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.
- Building Compressed NFTs on Solana with Generative SVG Art
A practical guide to creating and minting compressed NFTs (cNFTs) on Solana using Metaplex Bubblegum, with animated SVG artwork generated from wallet addresses.