Nidhi Jagga’s Post

𝐉𝐚𝐯𝐚 𝐝𝐞𝐯𝐬: "𝐈 𝐡𝐚𝐯𝐞 𝟓 𝐞𝐥𝐞𝐠𝐚𝐧𝐭 𝐦𝐞𝐭𝐡𝐨𝐝𝐬 𝐰𝐢𝐭𝐡 𝐭𝐡𝐞 𝐬𝐚𝐦𝐞 𝐧𝐚𝐦𝐞." 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐝𝐞𝐯𝐬: "𝐈 𝐡𝐚𝐯𝐞 𝟏 𝐦𝐞𝐭𝐡𝐨𝐝 𝐚𝐧𝐝 𝐚 𝐭𝐞𝐫𝐫𝐢𝐟𝐲𝐢𝐧𝐠 𝐰𝐚𝐥𝐥 𝐨𝐟 𝐢𝐟-𝐬𝐭𝐚𝐭𝐞𝐦𝐞𝐧𝐭𝐬." 🧱 Let's talk about Overriding vs. Overloading, and how JavaScript handles (or completely ignores) them. 🥊 𝐌𝐞𝐭𝐡𝐨𝐝 𝐎𝐯𝐞𝐫𝐫𝐢𝐝𝐢𝐧𝐠 (𝐓𝐡𝐞 𝐂𝐡𝐢𝐥𝐝 𝐑𝐞𝐛𝐞𝐥𝐥𝐢𝐨𝐧) This is when a child class inherits from a parent but decides it knows better. You redefine the exact same method with the exact same name. 𝑇ℎ𝑒 𝑅𝑒𝑎𝑙𝑖𝑡𝑦: It’s great until you realize you actually needed the parent's original logic too, so you awkwardly sprinkle in a `super.doSomething()` at the last second to avoid breaking the entire application. 🤹 𝐌𝐞𝐭𝐡𝐨𝐝 𝐎𝐯𝐞𝐫𝐥𝐨𝐚𝐝𝐢𝐧𝐠 (𝐓𝐡𝐞 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐈𝐥𝐥𝐮𝐬𝐢𝐨𝐧) In strictly typed languages, you can create multiple methods with the exact same name as long as they take different parameters. 𝑇ℎ𝑒 𝐽𝑆 𝑅𝑒𝑎𝑙𝑖𝑡𝑦: JavaScript literally does not care. If you write two functions with the same name, the bottom one just violently overwrites the top one. 𝑇ℎ𝑒 𝑊𝑜𝑟𝑘𝑎𝑟𝑜𝑢𝑛𝑑: We have to fake it. We create one massive function, pass in `...args`, and write 15 `if/else` blocks checking the argument lengths and `typeof` just to figure out what the frontend is actually trying to send us. JavaScript doesn't give you overloading natively; it gives you trust issues and a giant switch statement. 𝐂𝐨𝐧𝐟𝐞𝐬𝐬𝐢𝐨𝐧 𝐭𝐢𝐦𝐞: 𝐖𝐡𝐚𝐭'𝐬 𝐭𝐡𝐞 𝐮𝐠𝐥𝐢𝐞𝐬𝐭 "𝐬𝐢𝐦𝐮𝐥𝐚𝐭𝐞𝐝 𝐨𝐯𝐞𝐫𝐥𝐨𝐚𝐝𝐢𝐧𝐠" 𝐟𝐮𝐧𝐜𝐭𝐢𝐨𝐧 𝐲𝐨𝐮'𝐯𝐞 𝐞𝐯𝐞𝐫 𝐡𝐚𝐝 𝐭𝐨 𝐰𝐫𝐢𝐭𝐞 𝐭𝐨 𝐦𝐚𝐤𝐞 𝐚 𝐟𝐞𝐚𝐭𝐮𝐫𝐞 𝐰𝐨𝐫𝐤? 𝐃𝐫𝐨𝐩 𝐲𝐨𝐮𝐫 𝐜𝐫𝐢𝐦𝐞𝐬 𝐢𝐧 𝐭𝐡𝐞 𝐜𝐨𝐦𝐦𝐞𝐧𝐭𝐬. 👇 #JavaScript #WebDevelopment #SoftwareEngineering #MERNStack #CodingHumor #DeveloperLife #TechTips #Frontend

  • text

To view or add a comment, sign in

Explore content categories