Skip to content

Commit

Permalink
Add Array.of method
Browse files Browse the repository at this point in the history
Referencing higgsjs#179, adds Array.of method
  • Loading branch information
Pamela Selle committed Jul 2, 2015
1 parent 81ba8a7 commit 199f69b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions source/stdlib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,11 @@ function array_reduceRight(callbackfn, initialValue)
return array_reduce_generic.call(this, callbackfn, initialValue, this.length - 1, -1, -1);
}

function array_of()
{
return array_slice.call(arguments)
}

// Setup Array.prototype
Array.prototype.toString = array_toString;
Array.prototype.toLocaleString = array_toString;
Expand All @@ -654,6 +659,7 @@ Array.prototype.map = array_map;
Array.prototype.filter = array_filter;
Array.prototype.reduce = array_reduce;
Array.prototype.reduceRight = array_reduceRight;
Array.of = array_of;

// Make the Array.prototype properties non-enumerable
for (p in Array.prototype)
Expand Down
15 changes: 15 additions & 0 deletions source/tests/01-stdlib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,17 @@ function test_array_syntax()
return 0;
}

function test_array_of()
{
if(!array_eq(Array.of(2,3), [2,3]))
return 1;

if(!array_eq(Array.of("some",4), ["some",4]))
return 2;

return 0;
}

function test()
{
var r = test_ctor();
Expand Down Expand Up @@ -525,6 +536,10 @@ function test()
if (r != 0)
return 1800 + r;

var r = test_array_of();
if (r != 0)
return 1900 + r;

return 0;
}

Expand Down

0 comments on commit 199f69b

Please sign in to comment.