Title

一:是什么

JavaScript中,new操作符用于创建一个给定构造函数的实例对象

例子

function Person(name, age){
    this.name = name;
    this.age = age;
}
Person.prototype.sayName = function () {
    console.log(this.name)
}
const person1 = new Person('Tom', 20)
console.log(person1)  // Person {name: "Tom", age: 20}
t.sayName() // 'Tom'

 

posted on 2023-01-17 02:06  chccee  阅读(25)  评论(0编辑  收藏  举报