Node.js – 工具类型 isProxy() 方法
util.types.isProxy() 方法检查传递的值是否是内置的 Proxy 实例。如果满足上述条件,则返回 True,否则返回 False。
语法
util.types.isProxy(value)
参数
仅接受一个参数 -
值 - 此输入值作为必需参数的输入,并检查它是否是 Proxy 实例。
它会根据传递的输入值返回 True 或 False。
示例 1
创建文件 "isProxy.js" 并复制以下代码段。创建完该文件后,使用 "node isProxy.js" 命令运行此代码。
// util.types.isProxy() Demo Example
// Importing the util module
const util = require('util');
// Defining proxy and target
const target = {};
const proxy = new Proxy(target, {});
// Passing a target as input
console.log("1. " + util.types.isProxy(target));
// Passing a Proxy instance as input
console.log("2. " + util.types.isProxy(proxy));输出
C:\home
ode>> node isFloat32Array.js 1. false 2. true
示例 2
// util.types.isProxy() Demo Example
// Importing the util module
const util = require('util');
// Defining proxy and target
const handler = {
get: function(obj, prop) {
return prop in obj ?
obj[prop] :
37;
}
};
const p = new Proxy({}, handler);
p.a = 1;
p.b = undefined;
console.log(p.a, p.b);
console.log('c' in p, p.c);
// Passing a target as input
console.log("1." + util.types.isProxy(handler));
// Passing a Proxy instance as input
console.log("2." + util.types.isProxy(p));输出
C:\home
ode>> node isInt8Array.js 1 undefined false 37 1.false 2.true
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 语言
C++
C#
MongoDB
MySQL
Javascript
PHP