当前位置:网站首页>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
边栏推荐
猜你喜欢

win10终端中如何切换磁盘

格密码入门

长时间序列遥感数据处理及在全球变化、物候提取、植被变绿与固碳分析、生物量估算与趋势分析等领域中的应用

ASP.NET商贸进销存管理系统源码(带数据库文档)源码免费分享

Zero-knowledge proof notes - private transaction, pederson, interval proof, proof of ownership

How to carry out AI business diagnosis and quickly identify growth points for cost reduction and efficiency improvement?

【C语言】指针和数组的深入理解(第三期)

【CAS:2306109-91-9 |胺-PEG4-脱硫生物素】价格

面试官:索引为什么会失效?

动态数组底层是如何实现的
随机推荐
vscode离线安装插件方法
dotnet 删除只读文件
如何进行AI业务诊断,快速识别降本提效增长点?
win10 uwp 使用 WinDbg 调试
Interviewer: How is the expired key in Redis deleted?
格密码入门
动态规划_双数组字符串
KubeSphere简介,功能介绍,优势,架构说明及应用场景
mdk5.14无法烧录
香港暂停进口俄罗斯部分地区禽肉及禽类产品
如何用好建造者模式
QT(41)-多线程-QTThread-同步QSemaphore-互斥QMutex
在vs code中进行本地调试和开启本地服务器
【学术相关】清华教授发文劝退读博:我见过太多博士生精神崩溃、心态失衡、身体垮掉、一事无成!...
ADB 安装 + 打驱动全教程
推荐系统_刘老师
【2022杭电多校5 1012题 Buy Figurines】STL的运用
关于 SAP 电商云 Spartacus UI SSR 的 state transfer 问题
How to make good use of builder mode
win10 uwp 使用 ScaleTransform 放大某个元素