💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## 创建对象的方法 1. **字面量** ~~~ var obj={ name:"赵云", type:"突进", skill:"抢人头" } ~~~ > 缺点:只能创建一次对象,复用性较差,如果要创建多个对象,代码冗余度太高 2. **构造函数** ~~~ function Person() { this.name = "cc"; //通过this关键字设置默认成员 var worker = 'coding'; //没有this关键字,对象创建后,该变量为非成员 this.age = 32; this.Introduce = function () { alert("My name is " + this.name + ".I'm " + this.age); }; alert("My name is " + this.name + ".I'm " + this.age); }; var person = new Person(); ~~~ 3. **通过object** ~~~ var person = new Object(); person.name = "cc"; person.age = 18; person.Introduce = function () { alert("My name is " + this.name + ".I'm " + this.age); }; person.Introduce(); ~~~ 4. **object.create**