This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

Properti function.displayName mengembalikan nama fungsi.


Ketika didefinisikan, properti displayName mengembalikan nama dari sebuah fungsi:

function doSomething() {}

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

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

popup.displayName = 'Show Popup';

console.log(popup.displayName); // "Show Popup"

Anda bisa mendefinisikan sebuah fungsi dengan sebuah display nama di function expression:

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

Anda bisa merubah  displayName dari sebuah fungsi secara dinamis:

var object = {
  // anonymous
  someMethod: function(value) {
    this.displayName = 'someMethod (' + value + ')';

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

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


Biasanya lebih banyak digunakan dengan console dan profiler melalui untuk menampilkan nama function.

Dengan menuliskan kode berikut, maka seharusnya akan menampilkan "function My Function()":

var a = function() {};
a.displayName = 'My Function';

a; // "function My Function()"


Bukan bagian dari spesifikasi.

Kompabilitas browser

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help! (en-US)
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support ? 13 (13) ? ? ?
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? ? ? ? ?