|
22 | 22 | (function() {
|
23 | 23 |
|
24 | 24 | var _toString = Object.prototype.toString,
|
| 25 | + _hasOwnProperty = Object.prototype.hasOwnProperty, |
25 | 26 | NULL_TYPE = 'Null',
|
26 | 27 | UNDEFINED_TYPE = 'Undefined',
|
27 | 28 | BOOLEAN_TYPE = 'Boolean',
|
|
39 | 40 | JSON.stringify(0) === '0' &&
|
40 | 41 | typeof JSON.stringify(Prototype.K) === 'undefined';
|
41 | 42 |
|
| 43 | + |
| 44 | + |
| 45 | + var DONT_ENUMS = ['toString', 'toLocaleString', 'valueOf', |
| 46 | + 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'constructor']; |
| 47 | + |
| 48 | + // Some versions of JScript fail to enumerate over properties, names of which |
| 49 | + // correspond to non-enumerable properties in the prototype chain |
| 50 | + var IS_DONTENUM_BUGGY = (function(){ |
| 51 | + for (var p in { toString: 1 }) { |
| 52 | + // check actual property name, so that it works with augmented Object.prototype |
| 53 | + if (p === 'toString') return false; |
| 54 | + } |
| 55 | + return true; |
| 56 | + })(); |
| 57 | + |
42 | 58 | function Type(o) {
|
43 | 59 | switch(o) {
|
44 | 60 | case null: return NULL_TYPE;
|
|
52 | 68 | }
|
53 | 69 | return OBJECT_TYPE;
|
54 | 70 | }
|
55 |
| - |
| 71 | + |
56 | 72 | /**
|
57 | 73 | * Object.extend(destination, source) -> Object
|
58 | 74 | * - destination (Object): The object to receive the new properties.
|
|
309 | 325 | if (Type(object) !== OBJECT_TYPE) { throw new TypeError(); }
|
310 | 326 | var results = [];
|
311 | 327 | for (var property in object) {
|
312 |
| - if (object.hasOwnProperty(property)) { |
| 328 | + if (_hasOwnProperty.call(object, property)) |
313 | 329 | results.push(property);
|
| 330 | + } |
| 331 | + |
| 332 | + // Account for the DontEnum properties in affected browsers. |
| 333 | + if (IS_DONTENUM_BUGGY) { |
| 334 | + for (var i = 0; property = DONT_ENUMS[i]; i++) { |
| 335 | + if (_hasOwnProperty.call(object, property)) |
| 336 | + results.push(property); |
314 | 337 | }
|
315 | 338 | }
|
| 339 | + |
316 | 340 | return results;
|
317 | 341 | }
|
318 | 342 |
|
|
0 commit comments