當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Lodash _.functions()用法及代碼示例

Lodash _.functions()方法c從給定的自己的可枚舉屬性創建一個函數屬性名稱數組目的

用法:

_.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));

輸出:

[ '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安裝lodash

相關用法


注:本文由純淨天空篩選整理自taran910大神的英文原創作品 Lodash _.functions() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。