创建对象
一、使用Object直接创建对象

二、使用JSON创建对象的语法(字面量方法)

三、使用function,函数名和其参数可以看成一个构造器用于构造对象

function Student(id,name){ this.id=id; this.name=name; this.scores=[ {subject:"html",score:90}, {subject:"js",score:90} ] } // prototype 原型 Student.prototype.sex="男"; Student.prototype.eat=function(food){ console.log("吃"+food); } var stu=new Student(10003,"张三"); var stu=new Student(10004,"张三2"); stu.eat("米饭"); console.log(stu.id); console.log(stu.sex);
链式编程
function Student(id,name){ this.id=id; this.name=name; this.eat=function(food){ console.log("吃"+food); return this }, this.sleep=function(){ console.log("睡"); return this } } var stu=new Student(1001,"张三"); // 链式编程 jquery $("#con ul").eq(a).show().siblings().hide(); stu.eat("").sleep().eat("").sleep();

浙公网安备 33010602011771号