Jav*_* IN 5 javascript closures
我正在执行以下代码
function Person(name, age){
this.name = name || "John";
this.age = age || 24;
this.displayName = function(){
console.log('qq ',this.name);
}
}
Person.name = "John";
Person.displayName = function(){
console.log('ww ',this.name);
}
var person1 = new Person('John');
person1.displayName();
Person.displayName();
Run Code Online (Sandbox Code Playgroud)
得到以下输出:
qq John
ww Person
Run Code Online (Sandbox Code Playgroud)
我不明白如何在第二个控制台中获取 this.name = Person
这来自JS MDNFunction.name中的解释
Function 对象的只读 name 属性指示创建函数时指定的函数名称,或者对于匿名创建的函数而言为“匿名”。
function doSomething() {}
doSomething.name; // "doSomething"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1043 次 |
| 最近记录: |