Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between uneval() and .toSource()

Tags:

javascript

What is the difference between uneval(...) and .toSource()?

The toSource() method returns a string representing the source code of the object.

The uneval() method creates an string representation of the source code of an Object.

like image 612
KOLANICH Avatar asked Dec 27 '13 14:12

KOLANICH


1 Answers

One takes a param, the other doesn't. That appears to be the only difference, although the use of both is discouraged.

uneval(object);

Object.toSource();
obj.toSource();

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/uneval https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toSource

Straight from those sites above:

Non-standard

This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

I'd stay away from this feature. There's likely a better way to accomplish what you're trying to do.

like image 69
Jamis Charles Avatar answered Oct 13 '22 13:10

Jamis Charles