1

Possible Duplicate:
Cloning an Object in Node.js

I want to clone a Cheerio function object, but am having problems using the regular methods.

So, say the object is $object, I have tried to clone it doing:

eval("var clone = " + $object.toString());

But then I get this error message:

var clone = [object Function]

Here's the output of the original $object

{ [Function: initialize]
  _root: 
   { type: 'root',
     name: 'root',
     parent: null,
     prev: null,
     next: null,
     children: [] } }

So, does anyone know how I can clone this thing (in a fast way?)

Community
  • 1
  • 1
Jelle De Loecker
  • 20,999
  • 27
  • 100
  • 142
  • 1
    See this post: http://stackoverflow.com/questions/5055746/cloning-an-object-in-node-js – Niels Jan 24 '13 at 20:49
  • 1
    `Object.toString()` does not return the source code for the function, i think firefox has `Object.toSource()` which would do that, but its not a standard function. Best to use something like what @Niels suggested – NickSlash Jan 24 '13 at 21:06
  • Use cheerio's .clone() method: https://cheerio.js.org#clone – jimbo Feb 06 '18 at 10:51

0 Answers0