chrome 下一段代码的理解
来源:互联网 发布:大数据的前沿技术培训 编辑:程序博客网 时间:2024/06/13 18:26
记一次 代码理解
//Depending on the browser, the console shows a live link to the object. If you don't expand the object within the console until after the line that adds the .age property runs then when you do expand you'll see that property. Is that what you mean? One way to avoid this is to use console.log("obj1", JSON.stringify(obj)), to log a snapshot of the object at that moment. // chrome 开发环境下var obj = {name:"小明"};console.log("obj1",obj);// 1. {name:"小明",age:10}obj.age = 10;// 2. {"name":"小明",age:10}console.log("obj2",obj);
为什么 第一个 log 的结果不是 {name:"小明"}
产生这种结果的原因在于:
1. 浏览器对于 console.log 的行为表现是不一样的
2. 在firefox和 IE11 下的 输出结果和我们预料的一样
3. 在 chrome 下可以通过 JSON.stringify() 函数把 obj对象 “正常” 输出出来
4. 小结: 无论结果如何在 代码中对成员变量的使用都是一致的,符合我们日常的认识。
var obj = {name:"小明"};if ("age" in obj) { console.log("obj1",obj);}obj.age = 10;console.log("obj2",obj);// {name:"小明",age:10}
所以说,这个现象还是浏览器的 特殊行为
阅读全文
0 0
- chrome 下一段代码的理解
- 一段理解nio的代码
- 一段代码对C++的理解
- linux下测试一段代码的执行时间
- 一段代码理解函数指针
- C# 一段代码理解”委托“
- 检验对finally理解是否透彻的一段代码
- opengl笔记——旋转,一段代码的理解
- 一段代码让你理解set和list的区别
- 一段代码让你理解二叉树的递归奥秘
- 块内像素循环的一段小代码理解
- 用于理解vtkPolyData和vtkCellArray的一段代码
- 一段不可思议的代码
- 一段写晕掉的代码
- 一段好玩的代码
- 一段有趣的代码
- 一段漏洞百出的代码
- 一段弃暗投明的代码
- 第8章_图论
- 机器学习:线性回归与Python代码实现
- 【POCO】POCO学习总结(三)——交叉编译
- jsp页面response重定向
- spring boot -- mysql断连
- chrome 下一段代码的理解
- gradle插件版本和gradle版本对应关系
- hash模板
- 快速接入环信
- codeforces 330B Road Construction
- python中的字典
- svn 日常
- dwg转dxf有什么好的操作方法
- centos访问Windows共享文件两种方式: