当前位置:网站首页>Common methods of js's new Function()
Common methods of js's new Function()
2022-08-04 20:56:00 【Meimei Technology】
The first way
//For functions that create a stringvar test = new Function('arg','console.log(arg+1)');test(2) ; //3// which is equivalent tovar test = function(arg) {console.log(arg + 1);}test(2); // 3Second way
var test = new Function(arg,'console.log(arg+1)');var arg = 2;test();//3The third way
We don't even need to explicitly pass arguments to this function.We use the apply method to call it.It automatically sets the context in which the function executes.That's why we can use this.arg inside functions.Here this points to the data object.
var data = {arg:2}var test = new Function('console.log(this.age+1)').apply(data); //3
Source Network Author: Planet Boy
边栏推荐
猜你喜欢
随机推荐
长时间序列遥感数据处理及在全球变化、物候提取、植被变绿与固碳分析、生物量估算与趋势分析等领域中的应用
C语言——青蛙跳台阶(递归)
【debug】postgres数据存储错乱
Feign 与 OpenFeign
dotnet 使用 lz4net 压缩 Stream 或文件
Desthiobiotin衍生物Desthiobiotin-PEG4-Amine/Alkyne/Azide/DBCO
Qt Designer生成的图形可以自适应窗口的大小变化
[Data Mining] Written Exam Questions for Sohu Data Mining Engineers
Comic | Two weeks after the boss laid me off, he hired me back and doubled my salary!
如何最简单、通俗地理解爬虫的Scrapy框架?
88.(cesium之家)cesium聚合图
Apache服务器配置多个站点
实现菜单拖拽排序
后缀式的计算
链栈的应用
经验分享|盘点企业进行知识管理时的困惑类型
vscode离线安装插件方法
Using Baidu EasyDL to realize forest fire early warning and identification
明明加了唯一索引,为什么还是产生了重复数据?
【TypeScript】深入学习TypeScript枚举









