aboutsummaryrefslogtreecommitdiff
path: root/files/id/web/javascript/reference/global_objects/function/displayname/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/id/web/javascript/reference/global_objects/function/displayname/index.html')
-rw-r--r--files/id/web/javascript/reference/global_objects/function/displayname/index.html123
1 files changed, 123 insertions, 0 deletions
diff --git a/files/id/web/javascript/reference/global_objects/function/displayname/index.html b/files/id/web/javascript/reference/global_objects/function/displayname/index.html
new file mode 100644
index 0000000000..952014983b
--- /dev/null
+++ b/files/id/web/javascript/reference/global_objects/function/displayname/index.html
@@ -0,0 +1,123 @@
+---
+title: Function.displayName
+slug: Web/JavaScript/Reference/Global_Objects/Function/displayName
+tags:
+ - Function
+ - JavaScript
+ - Property
+translation_of: Web/JavaScript/Reference/Global_Objects/Function/displayName
+---
+<div>{{JSRef}} {{non-standard_header}}</div>
+
+<p>Properti <code><strong><em>function</em>.displayName</strong></code> mengembalikan nama fungsi.</p>
+
+<h2 id="Deskripsi">Deskripsi</h2>
+
+<p>Ketika didefinisikan, properti <code>displayName</code> mengembalikan nama dari sebuah fungsi:</p>
+
+<pre class="brush: js">function doSomething() {}
+
+console.log(doSomething.displayName); // "undefined"
+
+var popup = function(content) { console.log(content); };
+
+popup.displayName = 'Show Popup';
+
+console.log(popup.displayName); // "Show Popup"
+</pre>
+
+<p>Anda bisa mendefinisikan sebuah fungsi dengan sebuah display nama di {{jsxref("Functions", "function expression", "", 1)}}:</p>
+
+<pre class="brush: js">var object = {
+ someMethod: function() {}
+};
+
+object.someMethod.displayName = 'someMethod';
+
+console.log(object.someMethod.displayName); // logs "someMethod"
+
+try { someMethod } catch(e) { console.log(e); }
+// ReferenceError: someMethod is not defined
+</pre>
+
+<p>Anda bisa merubah  <code>displayName</code> dari sebuah fungsi secara dinamis:</p>
+
+<pre class="brush: js">var object = {
+ // anonymous
+ someMethod: function(value) {
+ this.displayName = 'someMethod (' + value + ')';
+ }
+};
+
+console.log(object.someMethod.displayName); // "undefined"
+
+object.someMethod('123')
+console.log(object.someMethod.displayName); // "someMethod (123)"
+</pre>
+
+<h2 id="Contoh">Contoh</h2>
+
+<p>Biasanya lebih banyak digunakan dengan console dan profiler melalui {{jsxref("Function.name", "func.name")}} untuk menampilkan nama function.</p>
+
+<p>Dengan menuliskan kode berikut, maka seharusnya akan menampilkan "<code>function My Function()</code>":</p>
+
+<pre class="brush: js">var a = function() {};
+a.displayName = 'My Function';
+
+a; // "function My Function()"</pre>
+
+<h2 id="Spesifikasi">Spesifikasi</h2>
+
+<p>Bukan bagian dari spesifikasi.</p>
+
+<h2 id="Kompabilitas_browser">Kompabilitas browser</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>