Underscore.JS - propertyOf 方法



語法

_.propertyOf(object)

propertyOf 方法返回一個函式,該函式將獲取一個物件並返回該物件的指定屬性。請看下面的示例 -

示例

var _ = require('underscore');

var student = {name: 'Sam', age: 10}

// Example: Get name of student
var getProperties = _.propertyOf(student);
console.log(getProperties('name'));

// Example 2: Get age of student
console.log(getProperties('age'));

將上述程式儲存在 tester.js 中。執行以下命令來執行此程式。

命令

\>node tester.js

輸出

Sam
10
underscorejs_updating_objects.htm
廣告
© . All rights reserved.