日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

JS报错-Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on...

發布時間:2023/12/31 javascript 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JS报错-Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

報錯信息:Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them;

也就是嚴格模式下,'caller', 'callee' 和??'arguments'不被允許,只能換一種方式寫了。

我項目之前都是OK的,沒報這個錯誤。后來,由于gitlab賬號的密碼修改了,我又沒配置永久的,所以需要重新拉代碼。

pull完npm install出錯(其實它有時就會出現一些不知名的問題,與項目并無關系的)。于是我用了yarn,然后打包上傳服務器在手機上測試時,就報了上述錯誤。代碼我沒改過,本地開發也是OK的,經過排查是打包問題(我懷疑是yarn install時,肯能某些文件install了嚴格模式,也說不過去,我也沒找到證據? ?/手動哭笑)。

還能咋滴,我只能改代碼咯。。。

(因為我在子組件向父組件emit一個方法,但是有2個參數,父組件在接收的時候,不能寫兩個參數,so,用了arguments

原有代碼

1.子組件

//子組件--vue文件 pick(date,_index){let hxDate = '';if(this.type == 'DAY'){ hxDate= timeFormat(date,'YMD')}if(this.type == 'WEEK'){ hxDate= String(date['wYear']) + String(date['wName'])}if(this.type == 'MONTH'){ hxDate= date['date']}if(this.type == 'YEAR'){ hxDate= date['date']} //傳了兩個參數this.$emit('getDate',hxDate,_index) }

2.父組件

//父組件--html文件(調用子組件) <date-calendar @getCalendar="getCalendarSale" @getDate="getDateT(arguments)" :type="type">// 代碼省略</date-calendar> //父組件---.vue文件 // 點擊年月進詳情頁面getDateT(value){console.log('點擊年月詳情getDate',value);}

3.打印結果

瀏覽器完全OK,打包就報Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them。。。氣哭 T_T

?

現有代碼

1.子組件

//子組件--vue文件 pick(date,_index){let hxDate = '';if(this.type == 'DAY'){ hxDate= timeFormat(date,'YMD')}if(this.type == 'WEEK'){ hxDate= String(date['wYear']) + String(date['wName'])}if(this.type == 'MONTH'){ hxDate= date['date']}if(this.type == 'YEAR'){ hxDate= date['date']}//將兩個參數組成數組再傳!!!let hGetDate = [];hGetDate.push(hxDate);hGetDate.push(_index);this.$emit('getDate',hGetDate) }

2.父組件

//父組件--html文件(調用子組件,一個參數可省略不寫) <date-calendar @getCalendar="getCalendarSale" @getDate="getDateT" :type="type">// 代碼省略</date-calendar> //父組件---.vue文件 // 點擊年月進詳情頁面getDateT(value){console.log('現有點擊年月詳情getDate',value);}

3.打印結果

?

?改成現有代碼之后,打包上傳服務器在手機上測試,OK,完美~

在查找過程中,也發現一個不錯的小tips:JS嚴格模式(use strict)下不能使用arguments.callee的替代方案,分享一下:

//一般在非嚴格模式下遞歸調用"use strict"; function factorial(num){if(num<=1){return 1;}else {return num * arguments.callee(num-1);} }console.log(factorial(4));報錯了,也是上述錯誤。//在嚴格模式下不能通過腳本訪問arguments.callee,訪問這個屬性會報錯,那么可以使用命名函數表達式來達到相同的結果,如下: "use strict"; var factorial = (function f(num){if(num<=1){return 1;}else {return num * f(num-1);} })console.log(factorial(4)); //24,正常打印

再看一段代碼

(function foo(bar) {if (bar) {return;}foo(true); })();

后記

以后遇到上述錯誤,一定要在相關代碼處查看你是否使用了'caller', 'callee', and 'arguments' ,然后換其他方式寫。

歡迎大佬指出不對的地方,多交流相互學習呀~

?

?

總結

以上是生活随笔為你收集整理的JS报错-Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。