mirror of
https://github.com/hanzoai/core-js.git
synced 2026-09-24 16:58:15 +00:00
Can build as library
Change callback args {Array::, Array, Object, Map, Set}reduceTo
Object::tie additional args & placeholder
add Function::by ???
38 lines
1013 B
JavaScript
38 lines
1013 B
JavaScript
$define(PROTO, 'Array', {
|
|
/**
|
|
* Alternatives:
|
|
* http://sugarjs.com/api/Array/at
|
|
* With Proxy: http://www.h3manth.com/new/blog/2013/negative-array-index-in-javascript/
|
|
*/
|
|
at: function(index){
|
|
return this[0 > (index |= 0) ? this.length + index : index];
|
|
},
|
|
/**
|
|
* Alternatives:
|
|
* http://underscorejs.org/#pluck
|
|
* http://sugarjs.com/api/Array/map
|
|
* http://api.prototypejs.org/language/Enumerable/prototype/pluck/
|
|
*/
|
|
pluck: function(key){
|
|
var that = ES5Object(this)
|
|
, length = toLength(that.length)
|
|
, result = Array(length)
|
|
, i = 0
|
|
, val;
|
|
for(; length > i; i++)if(i in that){
|
|
val = that[i];
|
|
result[i] = val == undefined ? undefined : val[key];
|
|
}
|
|
return result;
|
|
},
|
|
reduceTo: reduceTo,
|
|
/**
|
|
* Alternatives:
|
|
* http://mootools.net/docs/core/Types/Array#Array:append
|
|
* http://api.jquery.com/jQuery.merge/
|
|
*/
|
|
merge: function(arrayLike){
|
|
push.apply(this, ES5Object(arrayLike));
|
|
return this;
|
|
}
|
|
}); |