第一种用(花括号括起来){} 赋值 给一个变量
var object = {};
第二种使用系统给我们定义好的new Object
var object = new Object();
第三种通过构造函数创建对象
function students (name,age,sex){
this.name = name;
this.age = age;
this.sex = sex;
}
let stu1 = new students('张三',18,'男')
console.log(stu1)
第四种通过原型创建对象
function studentsPlay (){
studentsPlay.say = function(){
alert('我们是某某学校的学生')
}
}
let stu1 = new studentsPlay()
let stu2 = new studentsPlay()
第五种混编模式
function students (name,age,sex){
this.name = name;
this.age = age;
this.sex = sex;
studentsPlay.say = function(){
console.log('我们是某某学校的学生')
}
students.Prototype.play = function(){console.log('打篮球')}
let stu1 = new students('张三',20,'男')
stu1.sty()
第六种工厂模式创建对象
function shops(name,price,color,url,date){
let object1 = {}
object1.name = name;
object1.price = price;
object1.color = color;
object1.url = url;
object1.date = date;
return object1
}
let info = shops('舒肤佳',10,'蓝色','广东','20201105')