es5.js (1978B)
1 var isES5 = (function(){ 2 "use strict"; 3 return this === undefined; 4 })(); 5 6 if (isES5) { 7 module.exports = { 8 freeze: Object.freeze, 9 defineProperty: Object.defineProperty, 10 getDescriptor: Object.getOwnPropertyDescriptor, 11 keys: Object.keys, 12 names: Object.getOwnPropertyNames, 13 getPrototypeOf: Object.getPrototypeOf, 14 isArray: Array.isArray, 15 isES5: isES5, 16 propertyIsWritable: function(obj, prop) { 17 var descriptor = Object.getOwnPropertyDescriptor(obj, prop); 18 return !!(!descriptor || descriptor.writable || descriptor.set); 19 } 20 }; 21 } else { 22 var has = {}.hasOwnProperty; 23 var str = {}.toString; 24 var proto = {}.constructor.prototype; 25 26 var ObjectKeys = function (o) { 27 var ret = []; 28 for (var key in o) { 29 if (has.call(o, key)) { 30 ret.push(key); 31 } 32 } 33 return ret; 34 }; 35 36 var ObjectGetDescriptor = function(o, key) { 37 return {value: o[key]}; 38 }; 39 40 var ObjectDefineProperty = function (o, key, desc) { 41 o[key] = desc.value; 42 return o; 43 }; 44 45 var ObjectFreeze = function (obj) { 46 return obj; 47 }; 48 49 var ObjectGetPrototypeOf = function (obj) { 50 try { 51 return Object(obj).constructor.prototype; 52 } 53 catch (e) { 54 return proto; 55 } 56 }; 57 58 var ArrayIsArray = function (obj) { 59 try { 60 return str.call(obj) === "[object Array]"; 61 } 62 catch(e) { 63 return false; 64 } 65 }; 66 67 module.exports = { 68 isArray: ArrayIsArray, 69 keys: ObjectKeys, 70 names: ObjectKeys, 71 defineProperty: ObjectDefineProperty, 72 getDescriptor: ObjectGetDescriptor, 73 freeze: ObjectFreeze, 74 getPrototypeOf: ObjectGetPrototypeOf, 75 isES5: isES5, 76 propertyIsWritable: function() { 77 return true; 78 } 79 }; 80 }