Javascript 我如何知道我继承了哪个对象
在javascript中,我如何知道哪个对象是空的? 比如说Javascript 我如何知道我继承了哪个对象,javascript,oop,Javascript,Oop,在javascript中,我如何知道哪个对象是空的? 比如说 function a() { this.c = 1; } function b() { this.d = 2; } b.prototype = new a(); 如何检查b是否从a继承 谢谢。试试这个 b.prototype.constructor.name 工作示例:试试这个 b.prototype.constructor.name 工作示例:使用b.prototype的构造函数属性或b的任何实例 fu
function a() {
this.c = 1;
}
function b() {
this.d = 2;
}
b.prototype = new a();
如何检查b是否从a继承
谢谢。试试这个
b.prototype.constructor.name
工作示例:试试这个
b.prototype.constructor.name
工作示例:使用
b.prototype
的构造函数属性或b
的任何实例
function a(){
this.c=1;
}
function b(){
this.d=2;
}
b.prototype=new a();
x = new b()
if(x.constructor == a){
// x (instance of b) is inherited from a
}
使用
b.prototype
的构造函数属性或b
的任何实例
function a(){
this.c=1;
}
function b(){
this.d=2;
}
b.prototype=new a();
x = new b()
if(x.constructor == a){
// x (instance of b) is inherited from a
}
使用:
使用:
你可能想要的
这还具有遍历整个原型链的优势,因此不管它是否是您可能想要的父母、祖父母等
这还具有遍历整个原型链的优势,因此无论它是父母、祖父母等为什么我发出警报(x.constructor);它的警报“function a(){this.c=1;}”,但是x.constructor==a在工作?@user1801625,因为a是一个具有字符串表示的函数
函数a(){this.c=1;}
为什么我发出警报(x.constructor);它发出警报“function a(){this.c=1;}”,但x.constructor==a是工作的?@user1801625,因为a是一个具有字符串表示形式的函数function a(){this.c=1;}