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.
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.
Be aware: Both, toSource and uneval, are proprietary non-standard features.
While uneval is a function, i.e. a window method independend from the subject, toSource is implemented as a method of the subject. Due to this fact, additional error handling needs to be done when using toSource. On the other hand, uneval is capable to handle variables not being initialized with an actual object.
for(let v of [null, undefined])
{
console.log(uneval(v));
try
{
console.log(v.toSource());
}
catch(e)
{
console.log(e.message);
}
}