We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
严格模式给作者提供了选择一个限制性更强语言变种的方式。
开启严格模式:在js文件或者函数顶部加上"use strict"。开启严格模式有两种方法:
"use strict"
function foo(){ "use strict" }
testvar = 4 //报错:严格模式下不允许未声明使用变量
testObject = {}; Object.defineProperty(testObject,"name",{ value : "wang", writable:false, }) testObject.name = "zhou"; //报错,严格模式下不允许分配只读属性
var testObj = new Object(); Object.preventExtensions(testObj); testObj.name = "wang"; //报错,严格模式下,无法为不可扩展的对象创建属性
var testvar = 10; delete testvar; //报错,严格模式不允许删除变量 function fun(){}; delete fun; //报错,严格模式下不允许删除函数 var testObj = {}; Object.defineProperty(testObj,"name",{ configurable : false, }) delete testObj.name; //报错,严格模式不允许删除对象属性的描述configurable为false的属性。
var testObj = { prop1 = 10, prop1 = 10, //报错,严格模式不允许对象定义相同的属性。 }
function test (name,name) { //报错,严格模式不允许函数定义相同的函数名。 return 1; }
//implements、interface 、package、private、protected、public、static、yield。
var testvar = 010; //报错 var testvar1 = \010; //报错
function testFunc(){ console.log(this) //非严格模式下,this指向window //严格模式下,this为undefined }
// var eval = 10; //报错
11.语句或块中声明函数 : 无法再语句或者块中声明函数
for(var i = 0 ; i<5 ; i++) { function tes(){} //没有报错 } if(true){ function test(){ //没报错 } }
eval("var testvar = 10"); console.log(testvar = 5); //报错,严格模式下,eval用法无效
var arguments = 10; //报错 function arguments(){}; //报错
function test(name){ arguments[0] = 1; console.log(name); //wang 不变 } test("wang")
function test(){ arguments.callee(); //报错 } test();
with(Math){ x = cos(3); //报错,严格模式下,不允许使用with y = tan(7); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
严格模式
严格模式给作者提供了选择一个限制性更强语言变种的方式。
开启严格模式:在js文件或者函数顶部加上"use strict"。开启严格模式有两种方法:
"use strict"
严格模式做了哪些限制
//implements、interface 、package、private、protected、public、static、yield。
// var eval = 10; //报错
11.语句或块中声明函数 : 无法再语句或者块中声明函数
The text was updated successfully, but these errors were encountered: