非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。
function
.displayName
property returns the display name of the function.
It is usually preferred by consoles and profilers over
func.name
to display the name of a function.
By entering the following in a console, it should display as something like "
function My Function()
":
var a = function() {};
a.displayName = 'My Function';
a; // "function My Function()"
When defined, the
displayName
property returns the display name of a function:
function doSomething() {}
console.log(doSomething.displayName); // "undefined"
var popup = function(content) { console.log(content); };
popup.displayName = 'Show Popup';
console.log(popup.displayName); // "Show Popup"
You can define a function with a display name in a 函数表达式 :
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
You can dynamically change the
displayName
of a function:
var object = {
// anonymous
someMethod: function(value) {
arguments.callee.displayName = 'someMethod (' + value + ')';
}
};
console.log(object.someMethod.displayName); // "undefined"
object.someMethod('123')
console.log(object.someMethod.displayName); // "someMethod (123)"
Not part of any standard.
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
displayName
非标
|
Chrome No | Edge No | Firefox 13 | IE No | Opera No | Safari No | WebView Android No | Chrome Android No | Firefox Android 14 | Opera Android No | Safari iOS No | Samsung Internet Android No | nodejs No |
完整支持
不支持
非标。预期跨浏览器支持较差。
Function
Function.arguments
Function.caller
Function.displayName
Function.length
Function.name
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()