JS构造函数内部用function声明的函数,与利用this声明的函数有何不同,为何function声明的函数,实例化后仍指向同一片内存,而this声明的函数反之
console.log()输出问题
// 请把代码文本粘贴到下方(请勿用图片代替代码)
function Person(age,name) { this.age = age; this.name = name; function showSex() { console.log("girl");
} this.say = function() {}
}
var p1 = new Person(); var p2 = new Person(); console.log("showSex函数",p1.showSex === p2.showSex);
console.log("say函数",p1.say === p2.say);
Person.prototype.run = function () { console.log("1米每秒");
} console.log("run函数",p1.run === p2.run); console.log("run函数",p1.run === Person.prototype.run); // 双等号和三等号在比较对象的时候是没有任何区别的。这一段输出结果为true,console.log("showSex函数",p1.showSex === p2.showSex); //true
精慕HU
汪汪一只猫
随时随地看视频慕课网APP
相关分类