当前位置:网站首页>JS报错-Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on...
JS报错-Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on...
2022-08-09 09:11:00 【云胡不喜?】
报错信息: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' ,然后换其他方式写。
欢迎大佬指出不对的地方,多交流相互学习呀~
边栏推荐
- 谷歌地图时代结束,怎么看高清卫星影像地图?
- 不支持关键字: 'Provider'
- canal工作原理及简单案例演示
- 缓存的使用姿势:缓存穿透了怎么办?
- 历史遗留问题
- parse <compoN> error: Custom Component‘name should be form of my-component, not myComponent or MyCom
- MySQL Leak Check (4) Stored Procedures and Cursors
- Failed to mount component: template or render function not defined.
- UE4 RTS frame selection function implementation
- Redis Basics
猜你喜欢
随机推荐
ASP.net中的数据库应用
历史遗留问题
makefile - 学习小结
支付宝小程序禁止页面弹性下拉或上拉
canal工作原理及简单案例演示
【环境搭建】tensorrt
TypeScript Brief (1)
How does STM32 know the usage of FLASH
【场景化解决方案】钉钉财务审批同步金蝶云星空
JS-常用方法整理
运行flutter项目时遇到的问题
【场景化解决方案】OA审批与金智CRM数据同步
SQL语言中的distinct说明
MVCC多版本并发控制
【培训课程专用】RPC模型:代码导读
parse <compoN> error: Custom Component‘name should be form of my-component, not myComponent or MyCom
TestNG使用教程详解
mysql进阶(三十一)常用命令汇总
Amplify Shader Editor手册 Unity ASE(中文版)
JMeter参数化4种实现方式