Files
core-js/src/array.js
T
zloirock e5ff47cc43 Library
Can build as library
Change callback args {Array::, Array, Object, Map, Set}reduceTo
Object::tie additional args & placeholder
add Function::by ???
2014-02-27 14:18:01 +07:00

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;
}
});