diff --git a/es6-shim.js b/es6-shim.js index 0205569f..e721182a 100644 --- a/es6-shim.js +++ b/es6-shim.js @@ -54,8 +54,21 @@ }); defineProperties(Array, { - of: function(iterable) { - return Array.prototype.slice.call(iterable); + from: function(iterable) { + var object = Object(iterable); + var array = []; + + for (var key = 0, length = object.length >>> 0; key < length; key++) { + if (key in object) { + array[key] = object[key]; + } + } + + return array; + }, + + of: function() { + return Array.prototype.slice.call(arguments); } }); @@ -203,7 +216,7 @@ })() }); - defineProperties(globall.Set, { + /*defineProperties(globall.Set, { of: function(iterable) { var object = Object(iterable); var set = Set(); @@ -216,5 +229,5 @@ return set; } - }); + });*/ }); diff --git a/test/array.js b/test/array.js index a617aec5..f9302dad 100644 --- a/test/array.js +++ b/test/array.js @@ -2,21 +2,27 @@ var expect = require('expect.js'); require('../'); describe('Array', function() { - describe('Array.of()', function() { + describe('Array.from()', function() { it('should create correct array from iterable', function() { (function() { - expect(Array.of(arguments)).to.eql([0, 1, 2]) + expect(Array.from(arguments)).to.eql([0, 1, 2]) })(0, 1, 2); (function() { - expect(Array.of(arguments)).to.eql([null, undefined, 0.1248, -0, 0]); + expect(Array.from(arguments)).to.eql([null, undefined, 0.1248, -0, 0]); })(null, undefined, 0.1248, -0, 0); }); it('should handle empty iterables correctly', function() { (function() { - expect(Array.of(arguments)).to.eql([]); + expect(Array.from(arguments)).to.eql([]); })(); }); }); + + describe('Array.of()', function() { + it('should create correct array from arguments', function() { + expect(Array.of(1, null, void 0)).to.eql([1, null, void 0]) + }); + }); });