memesearch
JavaScript Clone Fails

JavaScript Clone Fails

Download Find similar pictures
Text on the meme
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
What it means

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.

Who
Objects
Tags
Source
Template
Khaby Lame shrug
Type
image
Size
800×700 · 72.6 KiB
Mood
sarcastic, absurd
Language
en
Added

Similar memes