This repository has been archived by the owner on Sep 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnatives.js
116 lines (111 loc) · 3.35 KB
/
natives.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
if (!Object.keys) {
Object.keys = (function () {
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
dontEnums = [
'toString',
'toLocaleString',
'valueOf',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'constructor'
],
dontEnumsLength = dontEnums.length;
return function (obj) {
if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
throw new TypeError('Object.keys called on non-object');
}
var result = [], prop, i;
for (prop in obj) {
if (hasOwnProperty.call(obj, prop)) {
result.push(prop);
}
}
if (hasDontEnumBug) {
for (i = 0; i < dontEnumsLength; i++) {
if (hasOwnProperty.call(obj, dontEnums[i])) {
result.push(dontEnums[i]);
}
}
}
return result;
};
}());
}
// Production steps of ECMA-262, Edition 5, 15.4.4.18
// Reference: http://es5.github.com/#x15.4.4.18
if (typeof Array.prototype.forEach === 'undefined') {
/**
* @param {function(*)} callback
* @param {*=} thisArg
* @name Array.forEach
*/
var forEach = function (callback, thisArg) {
var T, k;
if (typeof this === 'undefined' || this === null) {
throw new TypeError(" this is null or not defined");
}
var O = Object(this);
var len = O.length >>> 0;
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
}
if (arguments.length > 1) {
T = thisArg;
}
k = 0;
while (k < len) {
var kValue;
if (k in O) {
kValue = O[k];
callback.call(T, kValue, k, O);
}
k++;
}
};
if (typeof Object.defineProperty === 'function') {
Object.defineProperty(Array.prototype, 'forEach',
{
value: forEach,
configurable: true,
enumerable: false,
writable: true
});
}
else {
Array.prototype.forEach = forEach;
}
}
if (typeof Object.key !== 'function') {
/**
* Gets a string that represents the name of the very first property of an object. This operation may be used in anonymous object types.
* @param obj {*}
* @returns {string}
*/
Object.key = function(obj) {
if (typeof obj === 'undefined' || obj === null)
return null;
for(var prop in obj) {
if (obj.hasOwnProperty(prop))
return prop;
}
return null;
}
}
if (typeof Object.clear !== 'function') {
/**
* Clears object properties
* @param {*} obj
*/
Object.clear = function(obj) {
if (typeof obj === 'undefined' || obj === null)
return;
var arr = [];
for (var key1 in obj)
if (obj.hasOwnProperty(key1)) arr.push(key1);
for (var key2 in arr) {
delete obj[key2];
}
}
}