aboutsummaryrefslogtreecommitdiff
path: root/files/pl/web/javascript/reference/global_objects/function/tostring/index.html
blob: 2f158219b9a2307cb66aa5a78a5589bf7b844cfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
title: Function.prototype.toString()
slug: Web/JavaScript/Referencje/Obiekty/Function/toString
tags:
  - Function
  - JavaScript
  - Method
  - Prototype
translation_of: Web/JavaScript/Reference/Global_Objects/Function/toString
---
<div>{{JSRef}}</div>

<h2 id="Podsumowanie" name="Podsumowanie">Podsumowanie</h2>

<p>Zwraca łańcuch znaków reprezentujący kod źródłowy funkcji.</p>

<h3 id="Sk.C5.82adnia" name="Sk.C5.82adnia">Składnia</h3>

<pre class="syntaxbox"><code><var>function</var>.toString(indentation)</code></pre>

<h3 id="Parametry" name="Parametry">Parametry</h3>

<dl>
 <dt><code>indentation</code> {{non-standard_inline}} {{obsolete_inline(17)}}</dt>
 <dd>The amount of spaces to indent the string representation of the source code. If <code>indentation</code> is less than or equal to <code>-1</code>, most unnecessary spaces are removed.</dd>
</dl>

<h2 id="Opis" name="Opis">Opis</h2>

<p>Obiekt {{jsxref("Function")}} przesłania metodę {{jsxref("Object.prototype.toString", "toString")}} obiektu {{jsxref("Function")}}; nie dziedziczy {{jsxref("Object.prototype.toString")}}. Dla obiektów <code>Function</code>, metoda <code>toString()</code> zwraca łańcuch znaków reprezentujący obiekt.</p>

<p>JavaScript wywołuje metodę <code>toString()</code> automatycznie, gdy {{jsxref("Function")}} jest reprezentowana jako wartość tekstowa lub kiedy <code>Function</code> jest odsyłana do połączenia łańcuchów znaków.</p>

<p>Dla obiektów {{jsxref("Function")}}, wbudowana metoda <code>toString)=</code> dekompiluje funkcję z powrotem do kodu JavaScript, który tę funkcję definiuje. Łańcuch znaków zawiera słowa kluczowe <code>function</code>, listę argumentów, nawiasy klamrowe oraz ciało funkcji.</p>

<p>Załóżmy na przykład, że masz poniższy kod, który definiuje obiektowy typ <code>Dog</code> i tworzy <code>theDog</code>, obiekt typu <code>Dog</code>:</p>

<pre class="brush:js">function Dog(name, breed, color, sex) {
   this.name = name
   this.breed = breed
   this.color = color
   this.sex = sex
}

theDog = new Dog( "Gabby", "Lab", "chocolate", "girl" );
</pre>

<p>W dowolnej chwili, gdy <code>Dog</code> jest użyty w kontekście jako łańcuch znaków, JavaScript automatycznie wywołuje funkcję <code>toString</code>, która zwraca poniższy łańcuch znaków:</p>

<pre class="brush: js">function Dog(name, breed, color, sex) { this.name = name; this.breed = breed; this.color = color; this.sex = sex; }</pre>

<h2 id="Zobacz_tak.C5.BCe" name="Zobacz_tak.C5.BCe">Zobacz także</h2>

<ul>
 <li>{{jsxref("Object.prototype.toString()")}}</li>
</ul>