9
9
*
10
10
***/
11
11
12
- // Flag allowing Object.keys to be enhanced
13
- var OBJECT_ENHANCEMENTS_FLAG = 'enhanceObject' ;
14
-
15
12
// Matches bracket-style query strings like user[name]
16
13
var DEEP_QUERY_STRING_REG = / ^ ( .+ ?) ( \[ .* \] ) $ / ;
17
14
@@ -25,9 +22,6 @@ var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
25
22
// Internal reference to check if an object can be serialized.
26
23
var internalToString = Object . prototype . toString ;
27
24
28
- // Reference to native Object.keys.
29
- var nativeObjectKeys = Object . keys ;
30
-
31
25
// Query Strings | Creating
32
26
33
27
function toQueryStringWithOptions ( obj , opts ) {
@@ -353,32 +347,17 @@ function clone(source, deep) {
353
347
// Keys/Values
354
348
355
349
function objectSize ( obj ) {
356
- return keysWithObjectCoercion ( obj ) . length ;
350
+ return getKeysWithObjectCoercion ( obj ) . length ;
357
351
}
358
352
359
- function keysWithObjectCoercion ( obj ) {
353
+ function getKeysWithObjectCoercion ( obj ) {
360
354
return getKeys ( coercePrimitiveToObject ( obj ) ) ;
361
355
}
362
356
363
- function getKeysWithCallback ( obj , fn ) {
364
- if ( isFunction ( fn ) ) {
365
- var keys = [ ] ;
366
- forEachProperty ( obj , function ( key ) {
367
- fn . call ( obj , key , obj ) ;
368
- keys . push ( key ) ;
369
- } ) ;
370
- return keys ;
371
- }
372
- return nativeObjectKeys ( obj ) ;
373
- }
374
-
375
- function getValuesWithCallback ( obj , fn ) {
357
+ function getValues ( obj , fn ) {
376
358
var values = [ ] ;
377
359
forEachProperty ( obj , function ( key , val ) {
378
360
values . push ( val ) ;
379
- if ( isFunction ( fn ) ) {
380
- fn . call ( obj , val , obj ) ;
381
- }
382
361
} ) ;
383
362
return values ;
384
363
}
@@ -496,34 +475,6 @@ function buildClassCheckMethods() {
496
475
} ) ;
497
476
}
498
477
499
- defineInstanceAndStatic ( sugarObject , {
500
-
501
- /***
502
- * @method keys(<obj>, [fn])
503
- * @returns Array
504
- * @polyfill ES5
505
- * @short Returns an array containing the keys in <obj>.
506
- * @extra Sugar enhances this method to allow an optional function that is
507
- * called for each key. Note that the order of returned keys is not
508
- * guaranteed.
509
- *
510
- * @callback fn
511
- *
512
- * key The key of the current iteration.
513
- * obj A reference to the object.
514
- *
515
- * @example
516
- *
517
- * Object.keys({ broken: 'wear' }) -> ['broken']
518
- * Object.keys({ broken: 'wear' }, function(key) {
519
- * // Called once for each key.
520
- * });
521
- *
522
- ***/
523
- 'keys' : fixArgumentLength ( getKeysWithCallback )
524
-
525
- } , [ ENHANCEMENTS_FLAG , OBJECT_ENHANCEMENTS_FLAG ] ) ;
526
-
527
478
defineStatic ( sugarObject , {
528
479
529
480
/***
@@ -573,10 +524,10 @@ defineStatic(sugarObject, {
573
524
defineInstanceAndStatic ( sugarObject , {
574
525
575
526
/***
576
- * @method has(<obj>, <key>, [allowPrototype ] = false)
527
+ * @method has(<obj>, <key>, [inherited ] = false)
577
528
* @returns Boolean
578
529
* @short Checks if <obj> has property <key>.
579
- * @extra Supports `deep properties`. If [allowPrototype ] is `true`,
530
+ * @extra Supports `deep properties`. If [inherited ] is `true`,
580
531
* properties defined in the prototype chain will also return `true`.
581
532
* The default of `false` for this argument makes this method suited
582
533
* to working with objects as data stores by default.
@@ -594,10 +545,10 @@ defineInstanceAndStatic(sugarObject, {
594
545
} ,
595
546
596
547
/***
597
- * @method get(<obj>, <key>, [allowPrototype ] = false)
548
+ * @method get(<obj>, <key>, [inherited ] = false)
598
549
* @returns Mixed
599
550
* @short Gets a property of <obj>.
600
- * @extra Supports `deep properties`. If [allowPrototype ] is `true`,
551
+ * @extra Supports `deep properties`. If [inherited ] is `true`,
601
552
* properties defined in the prototype chain will also be returned.
602
553
* The default of `false` for this argument makes this method suited
603
554
* to working with objects as data stores by default.
@@ -802,7 +753,7 @@ defineInstanceAndStatic(sugarObject, {
802
753
* @method add(<obj1>, <obj2>, [options])
803
754
* @returns Object
804
755
* @short Merges properties in <obj1> and <obj2> and returns a new object.
805
- * @extra See `merge` for options.
756
+ * @extra This method will not modify either object. See `merge` for options.
806
757
*
807
758
* @example
808
759
*
@@ -855,7 +806,7 @@ defineInstanceAndStatic(sugarObject, {
855
806
* @returns Merged object
856
807
* @short Merges properties from one or multiple <sources> into <target> while
857
808
* preserving <target>'s properties.
858
- * @extra See `merge` for options.
809
+ * @extra This method modifies <target>! See `merge` for options.
859
810
*
860
811
* @example
861
812
*
@@ -884,27 +835,19 @@ defineInstanceAndStatic(sugarObject, {
884
835
} ,
885
836
886
837
/***
887
- * @method values(<obj>, [fn] )
838
+ * @method values(<obj>)
888
839
* @returns Array
889
- * @short Returns an array containing the values in <obj>. Optionally calls
890
- * [fn] for each value.
891
- * @extra Values are in no particular order.
892
- *
893
- * @callback fn
894
- *
895
- * val The value of the current iteration.
896
- * obj A reference to the object.
840
+ * @short Returns an array containing the values in <obj>.
841
+ * @extra Values are in no particular order. Does not include inherited or
842
+ * non-enumerable properties.
897
843
*
898
844
* @example
899
845
*
900
- * Object.values({ broken: 'wear' }) -> ['wear']
901
- * Object.values(usersByName, function(user) {
902
- * // Called once for each user.
903
- * });
846
+ * Object.values({a:'a',b:'b'}) -> ['a','b']
904
847
*
905
848
***/
906
- 'values' : function ( obj , fn ) {
907
- return getValuesWithCallback ( obj , fn ) ;
849
+ 'values' : function ( obj ) {
850
+ return getValues ( obj ) ;
908
851
} ,
909
852
910
853
/***
@@ -975,9 +918,9 @@ defineInstanceAndStatic(sugarObject, {
975
918
/***
976
919
* @method isObject(<obj>)
977
920
* @returns Boolean
978
- * @short Returns true if <obj> is a plain object.
979
- * @extra Does not include instances of classes or "host" objects, such as
980
- * Elements, Events, etc.
921
+ * @short Returns true if <obj> is a " plain" object.
922
+ * @extra Plain objects do not include instances of classes or "host" objects,
923
+ * such as Elements, Events, etc.
981
924
*
982
925
* @example
983
926
*
@@ -992,7 +935,7 @@ defineInstanceAndStatic(sugarObject, {
992
935
* @method remove(<obj>, <search>)
993
936
* @returns Object
994
937
* @short Deletes all properties in <obj> matching <search>.
995
- * @extra This method implements `enhanced matching`.
938
+ * @extra This method will modify <obj>!. Implements `enhanced matching`.
996
939
*
997
940
* @callback search
998
941
*
@@ -1014,8 +957,8 @@ defineInstanceAndStatic(sugarObject, {
1014
957
* @method exclude(<obj>, <search>)
1015
958
* @returns Object
1016
959
* @short Returns a new object with all properties matching <search> removed.
1017
- * @extra This is a non-destructive version of `remove`. This method
1018
- * implements `enhanced matching`.
960
+ * @extra This is a non-destructive version of `remove` and will not modify
961
+ * <obj>. Implements `enhanced matching`.
1019
962
*
1020
963
* @callback search
1021
964
*
0 commit comments