国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > WEB開發(fā) > 正文

js的嚴(yán)格模式總結(jié)

2024-04-27 15:05:01
字體:
供稿:網(wǎng)友
//變量 要聲明 /*"use strict"; a='liuynag'; console.log(a);//Uncaught ReferenceError: a is not defined*///不能調(diào)用delete // "use strict"; /*var color='red'; console.log(color); delete color;//Delete of an unqualified identifier in strict mode. console.log(color);*///不能將保留字作為變量名 /* "use strict"; var public='hah'; console.log(public);//Unexpected strict mode reserved Word*///嚴(yán)格模式 對象重名屬性報(bào)錯(cuò) /*"use strict"; var person={ name:'hahhha', name:'greg' } console.log(person.name);//編輯器報(bào)錯(cuò),瀏覽器沒有*///重名參數(shù) /*"use strict"; function a(num,num){ console.log(num);// Duplicate parameter name not allowed in this context console.log(arguments[1]); console.log(a.length); } a(11,12);*///arguments對象 // "use strict"; /*function a(num,num1){ num=2; console.log(arguments[0]);//嚴(yán)格11 不嚴(yán)格 2 } a(11,12);*///淘汰了arguments.callee arguments.caller // "use strict" /*function factorial(num){ if(num<=1){ return 1; }else{ return num*arguments.callee(num-1); } } console.log(factorial(5));//'caller', 'callee', and 'arguments' PRoperties may not be accessed on strict mode functions or the arguments objects for calls to them*///嚴(yán)格模式下 if語句不能創(chuàng)建函數(shù) 預(yù)編譯不會(huì)提到if語句外 /*"use strict" if(true){ function dosomething(){ console.log("好像沒出錯(cuò)"); } }else{ //寫完 } dosomething();//ReferenceError: dosomething is not defined*///eval(),它將不再包含上下文中創(chuàng)建函數(shù)或者變量; /*"use strict" function dosomething(){ eval("var x=10"); console.log(x);//: x is not defined } dosomething()*///eval()在嚴(yán)格模式下只有在被求值的特殊作用域下有效,隨后被銷毀 /*"use strict" var result=eval("var x=10,y=11;x+y"); alert(result);//21*///抑制this /*"use strict" var color='red'; function color1(){ console.log(this.color); } color1(null);//嚴(yán)格Cannot read property 'color' of undefined 不嚴(yán)格 red*///拋棄了with語句 /*"use strict" with(location){ alert(href);////嚴(yán)格Strict mode code may not include a with statement不嚴(yán)格 一段地址 }*///拋棄8進(jìn)制,0開頭不屬于8進(jìn)制 /*"use strict"; var value='010'; console.log(parseInt(value));//不嚴(yán)格8 嚴(yán)格10*/
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 吉木萨尔县| 乌兰察布市| 田东县| 泰和县| 邹平县| 泰安市| 遵化市| 获嘉县| 云林县| 临泉县| 高要市| 翁源县| 拜城县| 河曲县| 乌兰察布市| 兴化市| 高邑县| 灌云县| 呼和浩特市| 朔州市| 泾阳县| 枝江市| 承德县| 鹤山市| 基隆市| 翁源县| 罗平县| 武邑县| 南宫市| 青浦区| 恩施市| 武宁县| 广东省| 龙海市| 壤塘县| 通山县| 楚雄市| 嘉义市| 金门县| 麻阳| 思南县|