// 字面量json
var student={
id:10001,
name:"李四",
scores:[
{subject:"html",score:90},
{subject:"JS",score:90}
]
}
// function
function Student(id,name){
this.id = id;
this.name = name;
this.scores = [
{subject:"html",score:90},
{subject:"JS",score:90}
]
}
Student.prototype.sex="女";
Student.prototype.eat=function(food){
console.log("吃"+food)
}
var stu=new Student(1000,"李四");
stu.eat("米饭");
console.log(stu.sex)
// Object
var stu2=new Object();
stu2.id=1000;
stu2.name="李四";
stu2.scores=[
{subject:"html",score:90},
{subject:"JS",score:90}
]
// 链式编程
function Student(id,name){
this.id = id;
this.name = name;
this.scores = [
{subject:"html",score:90},
{subject:"JS",score:90}
],
this.eat=function(food){
console.log("吃"+food)
return this
},
this.sleep=function(){
console.log("睡")
return this
}
}
var stu=new Student(1001,"李四");
stu.eat("螺蛳粉加鸡爪").sleep().eat("螺蛳粉加鸡爪").sleep();
function Student(id,name){
this.id = id;
this.name = name;
this.scores = [
{subject:"html",score:90},
{subject:"JS",score:90}
],
this.noeat=function(food){
console.log("不吃"+food)
return this
},
this.nosleep=function(){
console.log("不睡")
return this
}
}
var stu=new Student(1001,"李四");
stu.noeat("螺蛳粉加鸡爪").nosleep().noeat("螺蛳粉加鸡爪").nosleep();

浙公网安备 33010602011771号