我是靠谱客的博主 矮小金针菇,最近开发中收集的这篇文章主要介绍JS——es5的严格模式(3)es5.0严格模式不让用的东西(arguments.callee和function.caller),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

 

视频:https://ke.qq.com/course/231577?taid=3983676656552089

"use strict"
            function test(){
                console.log(arguments.callee);
            }
            test();

callee,caller和arguments的其他的属性不能被通过在严格模式的function里面。

"use strict"
            function test(){
                console.log(test.caller);
            }
            function demo(){
                test();
            }
            demo();

4.2

变量赋值前必须声明

"use strict"
            var a = b = 3;

变量赋值前必须声明!

4.3

局部this必须被赋值(Person.call(null,undefined)赋值什么就是什么)

以前:预编译的过程this指向Window。

"use strict"
            function test(){
                console.log(this);
            }
            test();

所以它规定了一件事,局部的this,预编译的时候是空,你这个this必须被赋值,赋值什么就是什么。如果你要是new的话,里面就是一个新对象。

现在:局部的this的指向是空。

全局呢:

"use strict"
            console.log(this);

还是Window,全局的东西没办法赋值,所以只能还是Window。

4.4

拒绝重复属性和参数。

在es3.0中,重复的参数是不报错的,比如:

function test(name,name){
                console.log(name);
            }
            test(1 , 2);

但是在es5.0中:

"use strict"
            function test(name,name){
                console.log(name);
            }
            test(1 , 2);

 

拒绝使用重复的属性名,但是不会报错。

"use strict"
            var obj = {
                name : "123",
                name : "234"
            }

eval();在它里面能把字符串当做代码执行。

"use strict"
            var a = 123;
            eval("console.log(a)");

尽管eval好使,但是规定在es3.0里面,eval是不允许使用的。eval是魔鬼。他能改变作用域。

https://www.nczonline.net/blog/2013/06/25/eval-isnt-evil-just-misunderstood/

https://blog.csdn.net/weixin_41559723/article/details/79254363

推荐两篇看过的非常好的博客.

最后

以上就是矮小金针菇为你收集整理的JS——es5的严格模式(3)es5.0严格模式不让用的东西(arguments.callee和function.caller)的全部内容,希望文章能够帮你解决JS——es5的严格模式(3)es5.0严格模式不让用的东西(arguments.callee和function.caller)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部