首页 > 试题广场 >

请问以下JS代码输出的结果是什么? class father

[单选题]
请问以下JS代码输出的结果是什么?
class father {
    constructor() {
        this.name = 'Jhon';
    }
    getNum() {
        console.log(117);
    }
    name() {
        console.log('Emir');
    }
};
const son = new father();
son.getNum();
father.prototype.getNum = function() {
    console.log(935);
}
son.getNum();
son.name();


  • 935、935、Emir
  • 935、935、报错
  • 117、935、Emir
  • 117、935、报错
属性name是通过构造函数挂载在对象实例上的,而方法name是在father原型上的。在实例化时,实例上的属性name覆盖了原型上的方法name
发表于 2025-10-16 21:59:02 回复(0)