File tree Expand file tree Collapse file tree 5 files changed +45
-0
lines changed
Expand file tree Collapse file tree 5 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ ## Unreleased
2+ - Adds [ ` Oolong.property ` ] [ property ] .
3+
4+ [ property ] : https://github.com/moll/js-oolong/blob/master/doc/API.md#Oolong.property
5+
16## 1.12.0 (Jun 26, 2015)
27- Adds [ ` Oolong.setPrototypeOf ` ] [ setPrototypeOf ] .
38
Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ For extended documentation on all functions, please see the
6565- [ .mapKeys] ( https://github.com/moll/js-oolong/blob/master/doc/API.md#Oolong.mapKeys ) (object, callback, [ thisArg] )
6666- [ .merge] ( https://github.com/moll/js-oolong/blob/master/doc/API.md#Oolong.merge ) (target, source...)
6767- [ .ownKeys] ( https://github.com/moll/js-oolong/blob/master/doc/API.md#Oolong.ownKeys ) (object)
68+ - [ .property] ( https://github.com/moll/js-oolong/blob/master/doc/API.md#Oolong.property ) (key)
6869- [ .reject] ( https://github.com/moll/js-oolong/blob/master/doc/API.md#Oolong.reject ) (object, callback, [ thisArg] )
6970- [ .setPrototypeOf] ( https://github.com/moll/js-oolong/blob/master/doc/API.md#Oolong.setPrototypeOf ) (object, prototype)
7071- [ .values] ( https://github.com/moll/js-oolong/blob/master/doc/API.md#Oolong.values ) (object)
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ Oolong.js API Documentation
2828- [ .mapKeys] ( #Oolong.mapKeys ) (object, callback, [ thisArg] )
2929- [ .merge] ( #Oolong.merge ) (target, source...)
3030- [ .ownKeys] ( #Oolong.ownKeys ) (object)
31+ - [ .property] ( #Oolong.property ) (key)
3132- [ .reject] ( #Oolong.reject ) (object, callback, [ thisArg] )
3233- [ .setPrototypeOf] ( #Oolong.setPrototypeOf ) (object, prototype)
3334- [ .values] ( #Oolong.values ) (object)
@@ -407,6 +408,16 @@ person.age = 42
407408Oolong .ownKeys (person) // => ["age"]
408409```
409410
411+ <a name =" Oolong.property " />
412+ ### Oolong.property(key)
413+ Returns a function that returns the given property of an object.
414+
415+ ** Examples** :
416+ ``` javascript
417+ var getName = Oolong .property (" name" )
418+ getName ({name: " John" }) // => "John
419+ ```
420+
410421<a name =" Oolong.reject " />
411422### Oolong.reject(object, callback, [ thisArg] )
412423Rejects all enumerable properties and returns a new object without those
Original file line number Diff line number Diff line change @@ -593,6 +593,21 @@ exports.merge = function merge(target) {
593593 */
594594exports . ownKeys = Object . keys
595595
596+ /**
597+ * Returns a function that returns the given property of an object.
598+ *
599+ * @example
600+ * var getName = Oolong.property("name")
601+ * getName({name: "John"}) // => "John
602+ *
603+ * @static
604+ * @method property
605+ * @param key
606+ */
607+ exports . property = function ( key ) {
608+ return function ( obj ) { return obj [ key ] }
609+ }
610+
596611/**
597612 * Rejects all enumerable properties and returns a new object without those
598613 * properties for which the given function returned truthy for.
Original file line number Diff line number Diff line change 1+ var $ = require ( "../.." )
2+
3+ describe ( "Oolong.property" , function ( ) {
4+ it ( "must return a function that returns the given property" , function ( ) {
5+ var obj = { name : "John" }
6+ $ . property ( "name" ) ( obj ) . must . equal ( "John" )
7+ } )
8+
9+ it ( "must return inherited properties" , function ( ) {
10+ var obj = Object . create ( { name : "John" } )
11+ $ . property ( "name" ) ( obj ) . must . equal ( "John" )
12+ } )
13+ } )
You can’t perform that action at this time.
0 commit comments