JavaScript Clone Fails
function clone(obj) { var copy; // Handle the 3 simple types, and null or undefined if (null == obj || "object" != typeof obj) return obj; // Handle Date if (obj instanceof Date) { copy = new Date(); copy.setTime(obj.getTime()); return copy; } // Handle Array if (obj instanceof Array) { copy = []; for (var i = 0, len = obj.length; i < len; i++) { copy[i] = clone(obj[i]); } return copy; } // Handle Object if (obj instanceof Object) { copy = {}; for (var attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]); } return copy; } throw new Error("Unable to copy obj! Its type isn't supported."); } newObj := refObj
A long JavaScript function carefully clones dates, arrays, and objects. Underneath, the shortcut “newObj := refObj” simply assigns the reference instead of making a copy, followed by Khaby Lame’s confused shrug. The meme is used to mock overcomplicated code or point out an obvious, much simpler solution.
code screenshot / скриншот кодаJavaScript function / функция JavaScriptprogramming text / текст программированияman shrugging / мужчина, пожимающий плечамиblue sports jacket / синяя спортивная курткаwooden door / деревянная дверьcartoon beaver / мультяшный бобрwhite background / белый фонassignment statement / оператор присваивания
- @profunctor_io / 7962 2022-05-27
- Template
- Khaby Lame shrug
- Type
- image
- Size
- 800×700 · 72.6 KiB
- Mood
- sarcastic, absurd
- Language
- en
- Added