Skip to content

Commit

Permalink
example code
Browse files Browse the repository at this point in the history
  • Loading branch information
pdallmer committed Sep 6, 2024
1 parent e9c5a19 commit c07868d
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions documentation/dynamicPolyfills.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,39 @@ input:

output:
```javascript
function arrayMap(callbackFn) {
var arr = [];
for (var i = 0; i < this.length; i++) {
arr.push(callbackFn(this[i], i, this));
}
return arr;
function DynamicPolyfillCaller() {
this.getType = function (callee) {
if (callee === Array || Object.prototype.toString.call(callee) === '[object Array]') {
return 'array';
} else if (callee === Object || Object.prototype.toString.call(callee) === '[object Object]' && typeof callee !== 'function') {
return 'object';
} else if (callee === String || typeof callee === 'string') {
return 'string';
} else if (callee === Number || typeof callee === 'number') {
return 'number';
}
return false;
};
this._functions = {
map: {
array: function (callbackFn) {
var arr = [];
for (var i = 0; i < this.length; i++) {
arr.push(callbackFn(this[i], i, this));
}
return arr;
}
}
};
this.getFunction = function (callee, funcName) {
return this._functions[funcName][this.getType(callee)];
};
return this;
}
;
var _dpf = new DynamicPolyfillCaller();
/******/(function () {
// webpackBootstrap
var __webpack_exports__ = {};
arrayMap.call([1, 2, 3], function (e) {
_dpf.getFunction([1, 2, 3], "map").call([1, 2, 3], function (e) {
return e * 2;
});
/******/
Expand Down

0 comments on commit c07868d

Please sign in to comment.