我正在写一篇关于函数对象的构造函数
属性的博客,并遇到了这一行:
The prototype property of a function Object has the constructor property set to the function itself
含义,如下函数对象
function Student(name,age) {
this.name = name;
this.age = age;
}
将有以下原型(prototype)
{构造函数:学生}
function Student() {
}
console.log(Student.prototype);
console.log(Student.prototype.constructor);
console.log(Student.prototype.constructor.prototype);
console.log(Student.prototype.constructor.prototype.constructor);
console.log(Student.prototype.constructor.prototype.constructor.prototype);
这意味着原型(prototype)具有constructor
属性,该属性设置为具有相同原型(prototype)对象的函数本身。这是否有某些原因,或者只是一种语言功能。我找不到任何在这里进行循环引用的理由。
任何帮助表示赞赏。谢谢。
最佳答案
prototype.constructor
属性设置为引用构造函数,以便该构造函数实例化的对象可以检查使用哪个构造函数来创建它们。
关于javascript - 构造函数原型(prototype)循环引用 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29116041/