
js原型
文章平均质量分 78
星雨668
这个作者很懒,什么都没留下…
展开
-
js __proto__、prototype、constructor的关系
一、 前言这篇文章涉及到js的原型和原型链,对这块内容不熟悉的同学,可以移步:js 的原型和原型链 这篇文章先了解一下。二、什么是constructor?constructor 是每个引用类型(数组,对象,函数)都会拥有的一个属性,而且这个属性指向了创建当前这个实例对象的构造函数(类)。class Foo{};let f1 = new Foo();console.log(f1); // {} 是一个空对象 console.log(f1.__proto__); // {constructo原创 2022-04-30 16:49:41 · 468 阅读 · 0 评论 -
js 原型和原型链
一、前言今天我们来学习老生常谈的两个问题:原型以及原型链;首先,来看一段代码: class Student{ constructor(name,age){ this.name = name; this.age = age; } introduce(){ console.log(`我是${this.name},年龄${this.age}岁`); } } const student = new Student('zhangsan',18); console.log(stud原创 2022-04-27 11:03:41 · 1535 阅读 · 0 评论