1 字面量的方式
//实例对象
var per1={
name:"路飞",
age:20,
sex:"男",
eat:function () {
console.log("吃臭豆腐");
},
readBook:function () {
console.log("亲热天堂");
}
};
2 调用系统的构造函数
//调用系统的构造函数
var per2=new Object();
per2.name="许仙";
per2.age=30;
per2.sex="男";
per2.eat=function () {
console.log("吃榴莲");
};
per2.play=function () {
console.log("这个小蛇真好玩");
};
function Person() {
}
console.log(per2 instanceof Object);
var dog=new Object();
3 自定义构造函数方式
function Person(name,age,sex) {
this.name=name;
this.age=age;
this.sex=sex;
this.play=function () {
console.log("天天打游戏");
};
}
var per=new Person("白素贞",18,"女");
console.log(per instanceof Person);
网友评论