Lodash _.noop() 方法
Lodash 是一个基于 underscore.js 的 JavaScript 库。 Lodash 有助于处理数组、字符串、对象、数字等。
Lodash _.noop()方法用于返回“未定义”,而与传递给它的参数无关。
句法:
_.noop()
参数:此方法可以采用任何类型的可选参数。
返回:此方法返回未定义。
示例 1:
Javascript
// Requiring the lodash library
const _ = require("lodash");
// Use of _.noop() method
let val = undefined;
let val2 = _.noop();
if (val == val2)
console.log("val and val2 are equal");
else
console.log(`val and val2 are not equal`);
Javascript
// Requiring the lodash library
const _ = require("lodash");
// Use of _.noop() method
let obj = new Object(_.noop())
console.log(`Object is ${obj.Object}`)
// Use of _.noop() method
let arr = new Array(_.noop())
console.log(`Array is ${arr[0]}`)
输出:
val and val2 are equal
示例 2:
Javascript
// Requiring the lodash library
const _ = require("lodash");
// Use of _.noop() method
let obj = new Object(_.noop())
console.log(`Object is ${obj.Object}`)
// Use of _.noop() method
let arr = new Array(_.noop())
console.log(`Array is ${arr[0]}`)
输出 :
Object is undefined
Array is undefined