aboutsummaryrefslogtreecommitdiff
path: root/files/pl/web/javascript/reference/global_objects/function/displayname/index.html
blob: c9fe6b741ac380a5d4365d622858033beafa15be (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
title: Function.displayName
slug: Web/JavaScript/Reference/Global_Objects/Function/displayName
translation_of: Web/JavaScript/Reference/Global_Objects/Function/displayName
original_slug: Web/JavaScript/Referencje/Obiekty/Function/displayName
---
<div>{{JSRef}} {{non-standard_header}}</div>

<p>Właściwość <code><strong><em>function</em>.displayName</strong></code> zwraca wyświetlaną nazwę funkcji.</p>

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

<p>Gdy jest zdefiniowana, wlaściwość <code>displayName</code> zwraca wyświetlaną nazwę funkcji:</p>

<pre class="brush: js">function doSomething() {}

console.log(doSomething.displayName); // "undefined"

var popup = function(content) { console.log(content); };

popup.displayName = 'Pokaż Popup';

console.log(popup.displayName); // "Pokaż Popup"
</pre>

<p>Możesz zdefiniować funkcję z wyświetlaną nazwą {{jsxref("Functions", "function expression", "", 1)}}:</p>

<pre class="brush: js">var object = {
  someMethod: function() {}
};

object.someMethod.displayName = 'jakaśMetoda';

console.log(object.someMethod.displayName); // logs "jakaśMetoda"

try { someMethod } catch(e) { console.log(e); }
// ReferenceError: jakaśMetoda is not defined
</pre>

<p>Możesz dynamicznie zmieniać <code>displayName </code>z funkcji:</p>

<pre class="brush: js">var object = {
  // anonymous
  someMethod: function(value) {
    this.displayName = 'jakaśMetoda (' + value + ')';
  }
};

console.log(object.someMethod.displayName); // "undefined"

object.someMethod('123')
console.log(object.someMethod.displayName); // "jakaśMetoda (123)"
</pre>

<h2 id="Przykłady">Przykłady</h2>

<p>Zazwyczaj preferowane jest przez konsole i profilery podczas {{jsxref("Function.name", "func.name")}} aby wyświetlić nazwę funkcji.</p>

<p>Umieszczony w konsoli powinien wyświetlić coś w rodzaju "<code>function Moja Funkcja()</code>":</p>

<pre class="brush: js">var a = function() {};
a.displayName = '<code>Moja Funkcja</code>';

a; // "function <code>Moja Funkcja</code>()"</pre>

<h2 id="Specyfikacja">Specyfikacja</h2>

<p>Nie jest częścią żadnej specyfikacji.</p>

<h2 id="Zgodność_z_przeglądarką">Zgodność z przeglądarką</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop(13)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>