js.array.statics.js 750 B

1234567891011121314151617
  1. // JavaScript 1.6 / Strawman array statics shim
  2. var $ = require('./$')
  3. , $export = require('./$.export')
  4. , $ctx = require('./$.ctx')
  5. , $Array = require('./$.core').Array || Array
  6. , statics = {};
  7. var setStatics = function(keys, length){
  8. $.each.call(keys.split(','), function(key){
  9. if(length == undefined && key in $Array)statics[key] = $Array[key];
  10. else if(key in [])statics[key] = $ctx(Function.call, [][key], length);
  11. });
  12. };
  13. setStatics('pop,reverse,shift,keys,values,entries', 1);
  14. setStatics('indexOf,every,some,forEach,map,filter,find,findIndex,includes', 3);
  15. setStatics('join,slice,concat,push,splice,unshift,sort,lastIndexOf,' +
  16. 'reduce,reduceRight,copyWithin,fill');
  17. $export($export.S, 'Array', statics);