// 创建对象
// 第一种 new object
var stu = new Object;
stu.iid = "1420"
stu.name = "网忘忘"
stu.ss = function() {
console.log("我爱学习");
}
stu.ss()
console.log(stu.iid, stu.name);
var stu1 = {
iid: "1421",
name: "网王王",
tt: function() {
console.log("干饭");
}
}
stu1.tt();
// 第二工厂函数
function re(qq, ww) {
return {
qw: qq,
qe: ww,
eat: function() {
console.log("你叫" + ww + "是吗?");
}
}
}
var tu = re("1422", "旺旺旺");
var tu1 = re("1423", "旺旺的");
tu.eat();
tu1.eat();
// 第三种 使用构造函数创建,其实就是创建了一个模板
function Student(stuid, stuname) {
this.tw = stuid,
this.qu = stuname,
this.study = function() {
console.log("我爱学习!");
}
}
var stu_1 = new Student("1400", "山丹");
stu_1.study()
console.log(stu_1 instanceof Student);
console.log(stu_1);
console.log(stu_1.constructor === Student);