原型链、严格模式、JS异常处理

一 原型链

 //原型链
    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异常处理

  1. try :语句测试代码块的错误。
  2. catch :语句处理错误。
  3. throw: 语句创建自定义错误。
  4. finally :语句在 try 和 catch 语句之后,无论是否有触发异常,该语句都会执行。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值