当前位置:网站首页>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); // 3
Second way
var test = new Function(arg,'console.log(arg+1)');var arg = 2;test();//3
The 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
边栏推荐
- 3. Byte stream and character stream of IO stream
- Oreo域名授权验证系统v1.0.6公益开源版本网站源码
- MySQL field type
- 零知识证明笔记——私密交易,pederson,区间证明,所有权证明
- win10 uwp 使用 WinDbg 调试
- 如何用好建造者模式
- Zero-knowledge proof - zkSNARK proof system
- Win10 uwp use ScaleTransform magnify an element
- 文章复现:超分辨率网络-VDSR
- About the state transfer problem of SAP e-commerce cloud Spartacus UI SSR
猜你喜欢
C语言——青蛙跳台阶(递归)
Oreo域名授权验证系统v1.0.6公益开源版本网站源码
Configure laravel queue method using fort app manager
After encountering MapStruct, the conversion between PO, DTO and VO objects is no longer handwritten
深度解析:为什么跨链桥又双叒出事了?
Zero-knowledge proof - zkSNARK proof system
Using Baidu EasyDL to realize forest fire early warning and identification
CAS :80750-24-9(脱硫生物素 NHS 酯)
Zero-knowledge proof notes - private transaction, pederson, interval proof, proof of ownership
无代码平台字段设置:基础设置入门教程
随机推荐
项目难管理?先学会用好甘特图(内附操作方法及实用模板)
链栈的应用
新式茶饮,卷完水果还能卷什么?
【C语言】指针和数组的深入理解(第三期)
C#移动OA办公系统源码(基于微信企业号)
帝国CMS仿核弹头H5小游戏模板/92game帝国CMS内核仿游戏网整站源码
【1403. 非递增顺序的最小子序列】
adb shell input keyevent 模拟按键事件
WIN10系统如何开启终端
1、File对象学习
如何找到某个 ABAP structure 某字段的源头来自哪个数据库表
嵌入式分享合集28
【学术相关】清华教授发文劝退读博:我见过太多博士生精神崩溃、心态失衡、身体垮掉、一事无成!...
基于单向链表结构的软件虚拟定时器的设计与构建
run command for node
【CAS:2306109-91-9 |胺-PEG4-脱硫生物素】价格
拒绝服务攻击DDoS介绍与防范
经验分享|盘点企业进行知识管理时的困惑类型
3、IO流之字节流和字符流
Desthiobiotin衍生物Desthiobiotin-PEG4-Amine/Alkyne/Azide/DBCO