📜  Lodash _.functions() 方法

📅  最后修改于: 2022-05-13 01:56:39.750000             🧑  作者: Mango

Lodash _.functions() 方法

Lodash _.functions() 方法从给定对象自己的可枚举属性创建一个函数属性名称数组

句法:

_.functions( object )

参数:此方法接受如上所述和如下所述的单个参数:

  • object:这是要检查的对象。

返回值:此方法返回一个属性数组。

示例 1:

Javascript
// Defining Lodash variable 
const _ = require('lodash'); 
  
  
// Defining object function
function GFGfunc() {
  this.Geek1 = _.constant('gfg');
  this.Geek2 = _.constant('gfg');
}
   
// Use of function
console.log(_.functions(new GFGfunc));


Javascript
// Defining Lodash variable 
const _ = require('lodash'); 
  
  
// Defining object function
function GFGfunc() {
  this.Geek1 = _.constant('gfg');
  this.Geek2 = _.constant('gfg');
}
  
GFGfunc.prototype.Geek3 = _.constant('gfg');
   
// Use of function
console.log(_.functions(new GFGfunc));


输出:

[ 'Geek1', 'Geek2' ]

示例 2:

Javascript

// Defining Lodash variable 
const _ = require('lodash'); 
  
  
// Defining object function
function GFGfunc() {
  this.Geek1 = _.constant('gfg');
  this.Geek2 = _.constant('gfg');
}
  
GFGfunc.prototype.Geek3 = _.constant('gfg');
   
// Use of function
console.log(_.functions(new GFGfunc));

输出:

[ 'Geek1', 'Geek2' ]

注意:这在普通 JavaScript 中不起作用,因为它需要安装 lodash 库,并且可以使用npm install lodash 安装