当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
[AGC] Build Service 1 - Cloud Function Example
密码学系列之:PEM和PKCS7,PKCS8,PKCS12
Using Baidu EasyDL to realize forest fire early warning and identification
数字IC设计中基本运算的粗略的延时估计
uwp ScrollViewer content out of panel when set the long width
【随记】新一天搬砖 --20220727
vs Code runs a local web server
【1403. 非递增顺序的最小子序列】
web 应用开发最佳实践之一:避免大型、复杂的布局和布局抖动
常用正则表达式[通俗易懂]
Oreo域名授权验证系统v1.0.6公益开源版本网站源码
使用堡塔应用管理器配置laravel队列方法
Oreo domain name authorization verification system v1.0.6 public open source version website source code
【TypeScript】深入学习TypeScript枚举
How to carry out AI business diagnosis and quickly identify growth points for cost reduction and efficiency improvement?
win10 uwp 使用 WinDbg 调试
win10 uwp 修改图片质量压缩图片
Desthiobiotin-PEG4-Azide_脱硫生物素-叠氮化物 100mg
构建Buildroot根文件系统(I.MX6ULL)
Apache服务器配置多个站点