function fn() {
"use strict";
//some code
}
"use strict"; var x; delete x;//报错Delete of an unqualified identifier in strict mode.(不合格的标识符)
function fn(a,a){
"use strict";
result=a+a;
console.log(result);
}
fn(2,4);//Duplicate parameter name not allowed in this context(重复的参数名称在此上下文中不允许)
function fn1(a,a){
"use strict";
result=a+a;
console.log(result);
}
fn1(2,4);//结果为8
"use strict" var x=089; console.log(x);//报错:Decimals with leading zeros are not allowed in strict mode.
fn(5);
function fn(a){
"use strict";
a = 42;
// return a==arguments[0];//返回false
console.log(a);//结果为42
console.log(arguments[0]);//结果为5,严格模式下arguments[0]表示这个调用方法的第一个参数 (不再追踪 参数的变化,在函数内部,参数a被重新赋值为42,但arguments[0]仍然为5.)
}
fn(5);
function fn(a){
a = 42;
// return a==arguments[0];//返回true
console.log(a);//结果为42
console.log(arguments[0]);//结果为42(追踪参数变化)
}
"use strict"; var eval=3;//报错:Unexpected eval or arguments in strict mode var argument=6;//同样报错
"use strict";
function fn(n){
if(n==0){
return 1;
}else{
return n*arguments.callee(n-1);
}
}
console.log(fn(5));//报错
function fn(n){//阶乘
if(n==0){
return 1;
}else{
return n*arguments.callee(n-1);
}
}
console.log(fn(5));//正常120
"use strict"
function fn1() {
var n1= fn1.caller;
console.log(n1);
}
function fn2() {
fn1();
}
fn2();//报错
function fn1() {
var n1= fn1.caller;//此例中caller指向调用它的函数(fn2)
console.log(n1);
}
function fn2() {
fn1();
}
fn2();// 结果打印出:function fn2(){ fn1( ) };
"use strict";
with(obj){
x;
}//报错:Strict mode code may not include a with statement
with(object instance)
{
//代码块
}
eg:function Clothes(){
this.color="red";
this.size="m";
this.price="cheap";
}
var c1=new Clothes();
with(c1){
var str="颜色:"+color+",尺寸:"+size+",价格:"+price;
document.write(str);
}//结果(颜色:red,尺寸:m,价格:cheap)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有