background preloader

Cloning

Facebook Twitter

Clone Native Javascript Object. Copying an Object in Javascript. Cloning javascript objects. Objects in javascript are assigned by reference.

Cloning javascript objects

Sometimes we want to make a deep copy of an object rather than copying a reference. There are several solutions for this problem, and unfortunately some solutions have disadvantages. Constructs with eval/uneval don't work with every browser. Clone() In JavaScript. My other essay provides source code and documentation for shallow copy, deep copy, and clone functions.

Clone() In JavaScript

If you came here searching for "javascript clone," it's probably what you want. This is more of an background piece on cloning in prototype-based languages. I recently did a google search for "javascript clone", and noticed there's a lot of confusion about cloning vs. copying out there. Keith Devens .com - Weblog: Javascript clone function - June 07, 2007. Javascript cloning objects. Object literals and inheritance.