프로젝트

일반

사용자정보

통계
| 개정판:

root / HServer / 00.Server / 00.Program / node_modules / object-keys / shim.js

이력 | 보기 | 이력해설 | 다운로드 (1.51 KB)

1
(function () {
2
        "use strict";
3

    
4
        // modified from https://github.com/kriskowal/es5-shim
5
        var has = Object.prototype.hasOwnProperty,
6
                toString = Object.prototype.toString,
7
                forEach = require('./foreach'),
8
                isArgs = require('./isArguments'),
9
                hasDontEnumBug = !({'toString': null}).propertyIsEnumerable('toString'),
10
                hasProtoEnumBug = (function () {}).propertyIsEnumerable('prototype'),
11
                dontEnums = [
12
                        "toString",
13
                        "toLocaleString",
14
                        "valueOf",
15
                        "hasOwnProperty",
16
                        "isPrototypeOf",
17
                        "propertyIsEnumerable",
18
                        "constructor"
19
                ],
20
                keysShim;
21

    
22
        keysShim = function keys(object) {
23
                var isObject = object !== null && typeof object === 'object',
24
                        isFunction = toString.call(object) === '[object Function]',
25
                        isArguments = isArgs(object),
26
                        theKeys = [];
27

    
28
                if (!isObject && !isFunction && !isArguments) {
29
                        throw new TypeError("Object.keys called on a non-object");
30
                }
31

    
32
                if (isArguments) {
33
                        forEach(object, function (value) {
34
                                theKeys.push(value);
35
                        });
36
                } else {
37
                        var name,
38
                                skipProto = hasProtoEnumBug && isFunction;
39

    
40
                        for (name in object) {
41
                                if (!(skipProto && name === 'prototype') && has.call(object, name)) {
42
                                        theKeys.push(name);
43
                                }
44
                        }
45
                }
46

    
47
                if (hasDontEnumBug) {
48
                        var ctor = object.constructor,
49
                                skipConstructor = ctor && ctor.prototype === object;
50

    
51
                        forEach(dontEnums, function (dontEnum) {
52
                                if (!(skipConstructor && dontEnum === 'constructor') && has.call(object, dontEnum)) {
53
                                        theKeys.push(dontEnum);
54
                                }
55
                        });
56
                }
57
                return theKeys;
58
        };
59

    
60
        module.exports = keysShim;
61
}());
62