The toSource method returns a literal representing the source code of an object. This can then be used to create a new object.
The toSource method returns a literal representing the source code of an object. This can then be used to create a new object. Although the toSource method is usually called by JavaScript behind the scenes, you can call it yourself. In the case of the built-in Object object, it returns a string indicating that the source code is not available, while, for instances of Object, it returns the source. With a user-defined object, toSource will return the JavaScript source that defines it.
Object.toSource()
function Object() { [native code] }
function Cat(breed, name, age)
{
this.breed = breed
this.name = name
this.age = age
}
Cat.toSource()
function Cat(breed, name, age) { this.breed = breed; this.name = name; this.age = age; }
Sheeba = new Cat("Manx", "Felix", 7)
Sheeba.toSource()
{breed:"Manx", name:"Felix", age:7}