JavaScript的class是原型继承的语法糖,实例通过__proto__链访问构造函数的prototype;constructor初始化属性,普通方法挂载到prototype,static方法挂载到类自身。
JavaScript 的 class 语法只是原型继承的语法糖,它本身不改变底层机制——所有实例依然通过 __proto__ 链访问构造函数的 prototype 对象。
class 定义类(含构造器与方法)定义一个类只需使用 class 关键字,内部用 constructor() 初始化实例属性,其他方法直接写函数名即可,**不需要逗号分隔**。
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
return `Hello, I'm ${this.name}`;
}
static describe() {
return "A human being";
}
}
constructor 是唯一特殊方法,省略时会默认提供空构造器greet)自动添加到 Person.prototype 上static 方法挂在 Person 函数自身,不进入原型链ReferenceError),必须先声明后使用class 实例的原型链长什么样创建实例后,其隐式原型指

prototype,而类的 prototype 的 constructor 指回类本身;若存在继承,还会多一层 __proto__ 指向父类的 prototype。
const p = new Person("Alice", 30);
console.log(p.__proto__ === Person.prototype); // true
console.log(Person.prototype.constructor === Person); // true
console.log(p.__proto__.__proto__ === Object.prototype); // true
__proto__ 都是 Person.prototype,不是 Person
Person.prototype 默认只有 constructor 和你定义的方法,没有实例属性__proto__,应通过 Object.setPrototypeOf() 或 extends 控制继承关系extends 实现继承时原型链如何连接子类通过 extends 继承父类后,有两层原型连接:实例 → 子类 prototype → 父类 prototype → Object.prototype;同时子类函数的 __proto__ 指向父类函数,实现静态方法继承。
class Student extends Person {
constructor(name, age, grade) {
super(name, age); // 必须调用,否则报错
this.grade = grade;
}
study() {
return `${this.name} is studying`;
}
}
Student.prototype.__proto__ === Person.prototype(方法继承的关键)Student.__proto__ === Person(所以能访问 Person.describe())super() 必须在 this 使用前调用,否则报 ReferenceError
constructor,会隐式添加 constructor(...args) { super(...args); }
真正容易被忽略的是:即使写了 class,你仍然得理解 prototype、__proto__ 和 constructor 三者的关系——因为调试时看到的属性来源、instanceof 判断、甚至 Babel 编译后的代码,全依赖这套原型链。写 class 不等于脱离原型,只是换了一种更可控的组织方式。