Compare Revisions

Object.prototype.toSource()

Change Revisions

Revision 81294:

Revision 81294 by Sevenspade on

Revision 81295:

Revision 81295 by Sevenspade on

Title:
toSource
toSource
Slug:
JavaScript/Reference/Global_Objects/Object/toSource
JavaScript/Reference/Global_Objects/Object/toSource
Content:

Revision 81294
Revision 81295
n20            Method of <a href="en/Core_JavaScript_1.5_Reference/On20            Method of <a href="en/Core_JavaScript_1.5_Reference/G
>bjects/Object">Object</a>>lobal_Objects/Object">Object</a>
n37      <code>toSource()</code>n37      <code><i>obj</i>.toSource()</code>
n55    <pre>n55    <pre class="eval">
n64    <ul>n
65      <li>For custom objects, <code>toSource</code> returns the J
>avaScript source that defines the object as a string. 
66      </li>
67    </ul>
nn66    </p>
67    <h4 name="Built-in_toString_methods">
68      Built-in <code>toString</code> methods
69    </h4>
70    <p>
71      Each core JavaScript object of a unique class that also pro
 >vides its own prototype object has a unique <code>toString</code>
 > method. The purpose of this method is to provide an appropriate 
 >value when JavaScript needs to convert that object into a string.
 > These objects are: {{wiki.template(':en/ToSource')}}
n80    <pre>n82    <pre class="eval">
81function Dog(name,breed,color,sex) {83function Dog(name, breed, color, sex) {
82   this.name=name84   this.name=name;
83   this.breed=breed85   this.breed=breed;
84   this.color=color86   this.color=color;
85   this.sex=sex87   this.sex=sex;
nn89 
87theDog = new Dog("Gabby","Lab","chocolate","girl")90theDog = new Dog("Gabby", "Lab", "chocolate", "girl");
n92    <pre>n95    <pre class="eval">
93theDog.toSource()96theDog.toSource();
97</pre>
98    <p>
99      returns
100    </p>
101    <pre class="eval">
94//returns ({name:"Gabby", breed:"Lab", color:"chocolate", sex:"gi102({name:"Gabby", breed:"Lab", color:"chocolate", sex:"girl"})
>rl"}) 
t100      <a href="en/Core_JavaScript_1.5_Reference/Objects/Object/tot108      <a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Ob
>String">toString</a>>ject/toString">toString</a>

Back to History