一、构建对象
方法一:
通过new Object()的方式创建对象
var obj=new Object(); //指定对象的方法 obj.name="张三"; obj.age=18; obj.sex="男"; //指定对象的方法 obj.show=function(){ alert(obj.name); }; //调用方法 obj.show();
方法二:
通过字面量方式创建对象
var objli={ //属性 name:"李四", age:18, sayhello:function(){ alert('大家好我是:'+this.name); } }; //调用方法 objli.sayhello();
方法三:
构造函数
function Student(name,age){ this.name=name; this.age=age; this.say=function(){ alert(this.name); } }; //调用构造函数 var stu=new Student('王五',19); stu.say();
二、原型
三、原型链关系图
四、判断对象类型
1、constructor
对象名.constructor==对象类型
2、instanceof
对象名 instanceof 对象类型