【发布时间】:2017-02-18 13:39:55
【问题描述】:
// 代码开始
function Person(name) {
this.name = name;
console.log(this.name); //Output 1
console.log(this); //Output 2
}
var p1 = new Person("Object_Shashank");
var p2 = Person("Function_Shashank");
// 代码结束
p1:
- 输出 1:Object_Shashank
- 输出 2:人员 {name: "Object_Shashank"}
p2:
- 输出 1:Function_Shashank
- 输出 2:窗口 {speechSynthesis:SpeechSynthesis,缓存:CacheStorage,localStorage:Storage,sessionStorage:Storage,webkitStorageInfo:DeprecatedStorageInfo…}
谁能解释一下“p2:输出2”
【问题讨论】:
-
Person()=window.Person() -
你在
Person之前忘记了new关键字
标签: javascript