-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmall_polyfilled.js
98 lines (86 loc) · 2.45 KB
/
small_polyfilled.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*jslint this:true, for:true, white: true, browser: true*/
/*global window*/
// ==ClosureCompiler==
// @output_file_name default.js
// @compilation_level ADVANCED_OPTIMIZATIONS
// ==/ClosureCompiler==
(function() {
"use strict";
// Object.create polyfill
if (typeof Object.create !== "function") {
Object.create = (function() {
/**
* @constructor
*/
var NewObject = function() {
return this;
};
return function(prototype) {
if (arguments.length > 1) {
throw new Error("Second argument not supported");
}
if (typeof prototype !== "object") {
throw new TypeError("Argument must be an object");
}
NewObject.prototype = prototype;
var result = new NewObject();
NewObject.prototype = {};
return result;
};
})();
}
// Object.assign polyfill
if (typeof Object.assign !== "function") {
/* eslint-disable no-unused-vars */
Object.assign = function(
target,
ignore // .length of function is 2
) {
if (
target === null ||
target === undefined // TypeError if undefined or null
) {
throw new TypeError("Cannot convert undefined or null to object");
}
var to = Object(target);
var nextSource;
var nextKey;
var index;
for (index = 1; index < arguments.length; index += 1) {
nextSource = arguments[index];
if (
nextSource !== null &&
nextSource !== undefined // Skip over if undefined or null
) {
for (nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
};
}
// Infinite Object
function branchFrom(parent) {
return function branchUsing(keyOrProps, value) {
var branch = Object.create(parent);
if (typeof keyOrProps === "string") {
branch[keyOrProps] = value;
} else if (typeof keyOrProps === "object") {
Object.assign(branch, keyOrProps);
}
Object.assign(branch, { branches: [], branch: branchFrom(branch) });
parent.branches.push(branch);
return branch;
};
}
function io() {
var root = {};
Object.assign(root, { branches: [], branch: branchFrom(root) });
return root;
}
window["io"] = io;
})();