METHOD:  Object::toSource Netscape Only Feature


Object.toSource()
 
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. The following examples illustrate these three cases:
 
Code:
Object.toSource()
 
Output:
function Object() { [native code] }
 
Code:
function Cat(breed, name, age)
{
   this.breed = breed
   this.name = name
   this.age = age
}
Cat.toSource()

 
Output:
function Cat(breed, name, age) { this.breed = breed; this.name = name; this.age = age; }
 
Code:
Sheeba = new Cat("Manx", "Felix", 7)
Sheeba.toSource()

 
Output:
{breed:"Manx", name:"Felix", age:7}


Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information