Skip to content

Commit 6699807

Browse files
committed
Merge pull request #504 from dmi3y/wsharraymap
Patch Array.prototype.map polyfil for JScript
2 parents f844802 + fe853bb commit 6699807

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/cli/wsh.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,39 @@ var wshapi = (function(){
7373
};
7474
}
7575

76+
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
77+
if (!Array.prototype.map)
78+
{
79+
Array.prototype.map = function(fun /*, thisArg */ ) {
80+
"use strict";
81+
82+
if (this === void 0 || this === null) {
83+
throw new TypeError();
84+
}
85+
86+
var t = Object(this);
87+
var len = t.length >>> 0;
88+
if (typeof fun !== "function") {
89+
throw new TypeError();
90+
}
91+
92+
var res = new Array(len);
93+
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
94+
for (var i = 0; i < len; i++) {
95+
// NOTE: Absolute correctness would demand Object.defineProperty
96+
// be used. But this method is fairly new, and failure is
97+
// possible only if Object.prototype or Array.prototype
98+
// has a property |i| (very unlikely), so use a less-correct
99+
// but more portable alternative.
100+
if (i in t) {
101+
res[i] = fun.call(thisArg, t[i], i, t);
102+
}
103+
}
104+
105+
return res;
106+
};
107+
}
108+
76109
function traverseDir(files, path) {
77110
var filename, folder = fso.GetFolder(path),
78111
subFlds, fc = new Enumerator(folder.files);

0 commit comments

Comments
 (0)