node.js JavaScript 严格模式

原创
2017/03/29 18:52
阅读数 148

严格模式 ,

特点:

  • 变量严格声明(使用 var 定义);
  • 禁止动态绑定,不能使用 with,eval 作用域,所以效率高
  • 不能删除变量 (和第一点只能用 var 定义变量有关,变量属性 configure为false)

使用严格模式

"use strict";

查看变量 configureable

[root@VM_235_218_centos ~]# node
> var tempStr1 = 'var create variable'
undefined
>
> Object.getOwnPropertyDescriptor(global,'tempStr1')
{ value: 'var create variable',
  writable: true,
  enumerable: true,
  configurable: false }
>
> tempStr2 = 'with out var'
'with out var'
>
> Object.getOwnPropertyDescriptor(global,'tempStr2')
{ value: 'with out var',
  writable: true,
  enumerable: true,
  configurable: true }
> 
> delete tempStr1
false
>
> delete tempStr2
true

> 

 

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部