一 原型链
//原型链
var arr=new Array();
console.log(arr);
console.log(arr.__proto__);//输出的是整个Array的原型对象
console.log(arr.__proto__.__proto__);//输出的是Object 的原型对象
console.log(arr.__proto__.__proto__.__proto__);//null 没有继承任何人的
console.log(arr.__proto__ == Array.prototype);//输出true
console.log(arr.__proto__.__proto__== Object.prototype);//输出true
console.log(Object.__proto__);//null
//Person类
function Person(){
this.color="";
this.sleep= function () {
}
}
//给person类添加原型对象
Person.prototype={
constructor:Person,
name:"",
sex:"",
eat: function () {
}
};
var p= new Person();
console.log(p);//
console.log(p.__proto__);//原型对象
console.log(p.__proto__.__proto__);//object
//子类
function Child(){
this.job="";
}
//原型继承 父类
Child.prototype=new Person();
var c=new Child();
console.log(c);
console.log(c.__proto__);//父类
console.log(c.__proto__.__proto__);//父类的原型对象
console.log(c.__proto__.__proto__.__proto__);//object 原型对象
console.log(c.__proto__.__proto__.__proto__.__proto__);//null
二 严格模式
严格模式必须按照JS的标准格式写,保证JS语句的准确性,便于给以后JS新版本的开发做铺垫。
三 JS异常处理
- try :语句测试代码块的错误。
- catch :语句处理错误。
- throw: 语句创建自定义错误。
- finally :语句在 try 和 catch 语句之后,无论是否有触发异常,该语句都会执行。