This repository has been archived by the owner on Apr 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proposal.js
254 lines (224 loc) · 5.71 KB
/
proposal.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
// -*- coding: utf-8; indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
/**
* Implementation of ECMAScript 6 (Draft)
* @requires: ECMAScript 5
* @author: Alexander Guinness <[email protected]>
* @version: 0.0.1
* @license: MIT
* @date: Thu Nov 1 00:08:00 2011
**/
void function(__object__, __array__, __global__)
{
'use strict';
var define = function(name)
{
var __own__ = __object__.hasOwnProperty;
if (__own__.call(this, name))
return 0;
var set = function(name, value, descriptor)
{
Object.defineProperty(this, name, descriptor || {
value: value,
configurable: true,
enumerable: false,
writable: true
});
};
if (__object__.toString.call(name) === '[object Object]')
{
for (var key in name) {
if (__own__.call(name, key))
set.call(this, key, name[key]);
}
}
else
set.apply(this, arguments);
};
/*
* ------------------------------------------------------------
* Object
* ------------------------------------------------------------
*/
/**
* Object.isObject
* @edition ECMA-262 6th Edition, 15.2.3.15
* Removed in Rev 9 July 8, 2012 ECMA-262 6 Draft
*
* @param {Object}
* @return {Boolean}
*
* @example:
*
* Object.isObject({}); // true
**/
define.call(Object, 'isObject', function(object) {
return object && __object__.toString.call(object) === '[object Object]';
});
/**
* Object.getOwnPropertyDescriptors
* @edition proposal
*
* Returns a property descriptor of the specified object, including object’s prototype chain
* @param {Object} object
* Object.getOwnPropertyDescriptor, Array.prototype.forEach
* @throws {TypeError}
* @return {Object}
*
* @example:
*
* var object = {};
*
* Object.defineProperty(object, 'a', {
* value: 1,
* configurable: false,
* enumerable: false,
* writable: false
* });
*
* Object.defineProperty(object, 'b', {
* value:2,
* configurable: true,
* enumerable: true,
* writable: true
* });
*
* Object.getOwnPropertyDescriptors(object);
*
* a: {
* value: 1,
* configurable: false,
* enumerable: false,
* writable: false
* },
*
* b: {
* value: 2,
* configurable: true,
* enumerable: true,
* writable: true
* }
**/
define.call(Object, 'getOwnPropertyDescriptors', function(object)
{
if (__object__.toString.call(object) !== '[object Object]')
throw new TypeError('Object.getOwnPropertyDescriptors: ' + object + ' is not an Object!');
var descriptors = {};
__array__.forEach.call(Object.getOwnPropertyNames(object), function (property)
{
Object.defineProperty(descriptors, property, {
value: Object.getOwnPropertyDescriptor(object, property),
configurable: false,
enumerable: true,
writable: false
});
});
return descriptors;
});
/**
* Object.getPropertyDescriptor
* @edition proposal
*
* Returns a property descriptor of the specified object, including object’s prototype chain
* @param {Object} object
* @param {String} name - The name of the property
* @throws {TypeError}
* @return {Object}
*
* @example:
*
* Object.getPropertyDescriptor({}, 'toString');
*
* {
* value: [Function: toString],
* writable: true,
* enumerable: false,
* configurable: true
* }
**/
define.call(Object, 'getPropertyDescriptor', function(object, name)
{
if (__object__.toString.call(object) !== '[object Object]')
throw new TypeError('Object.getPropertyDescriptor: ' + object + ' is not an Object!');
var descriptor = Object.getOwnPropertyDescriptor(object, name),
__proto__ = Object.getPrototypeOf(object);
while (descriptor === undefined && __proto__ !== null) {
descriptor = Object.getOwnPropertyDescriptor(__proto__, name);
__proto__ = Object.getPrototypeOf(__proto__);
}
return descriptor;
});
/**
* Object.getPropertyNames
* Returns an array of all the names of the properties
*
* @param {Object} object
* @throws {TypeError}
* @edition proposal
* @return {Array}
*
* @example:
*
* Object.getPropertyNames({});
*
* [
* 'toString',
* 'toLocaleString',
* 'hasOwnProperty',
* 'valueOf',
* 'constructor',
* 'propertyIsEnumerable',
* 'isPrototypeOf',
* ]
**/
define.call(Object, 'getPropertyNames', function(object)
{
if (__object__.toString.call(object) !== '[object Object]')
throw new TypeError('Object.getPropertyNames: ' + object + ' is not an Object!');
var properies = Object.getOwnPropertyNames(object),
__proto__ = Object.getPrototypeOf(object);
while (__proto__ !== null)
{
__array__.forEach.call(Object.getOwnPropertyNames(__proto__), function(property) {
if (properies.indexOf(property) === -1)
properies.push(property);
});
__proto__ = Object.getPrototypeOf(__proto__);
}
return properies;
});
/**
* Object.isnt
* Opposed to the Object.isnt
*
* @param {*} - first generic value for egal comparison
* @param {*} - second generic value for egal comparison
* @requires Object.is
* @return {Boolean}
*
* @example:
*
* Object.isnt(0, 0) // false
**/
define.call(Object, 'isnt', function(x, y) {
return !Object.is(x, y);
});
/**
* String.prototype.toArray
* @edition ECMA-262 6th Edition, 15.5.4.25
* Removed in Rev 9 July 8, 2012 ECMA-262 6 Draft
*
* Creates an array from the specified String object
* @return {Array} Returns an Array object with elements corresponding to
* the characters of this object (converted to a String).
*
* @example:
*
* Hello'.toArray() // ['H', 'e', 'l', 'l', 'o'];
**/
define.call(String.prototype, 'toArray', function() {
return this.split('');
});
}
(Object.prototype, Array.prototype, function() {
return this;
}());