new 实现
构造函数和实例化js中可以通过构造函数批量创建对象,创建的过程通过new关键词实现,这个过程也叫实例化,实例化的对象具有默认的属性和原型方法1234567891011function Person(name, age) { this.name = name; this.age = age;}Person.prototype.sayHello = function() { console.log(`My name is ${this.name}, I'm ${this.age} years old`);}...
阅读全文…