73 lines
1.7 KiB
JavaScript
73 lines
1.7 KiB
JavaScript
|
var isES5 = (function(){
|
||
|
"use strict";
|
||
|
return this === undefined;
|
||
|
})();
|
||
|
|
||
|
if (isES5) {
|
||
|
module.exports = {
|
||
|
freeze: Object.freeze,
|
||
|
defineProperty: Object.defineProperty,
|
||
|
keys: Object.keys,
|
||
|
getPrototypeOf: Object.getPrototypeOf,
|
||
|
isArray: Array.isArray,
|
||
|
isES5: isES5,
|
||
|
propertyIsWritable: function(obj, prop) {
|
||
|
var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
|
||
|
return !!(!descriptor || descriptor.writable || descriptor.set);
|
||
|
}
|
||
|
};
|
||
|
} else {
|
||
|
var has = {}.hasOwnProperty;
|
||
|
var str = {}.toString;
|
||
|
var proto = {}.constructor.prototype;
|
||
|
|
||
|
var ObjectKeys = function (o) {
|
||
|
var ret = [];
|
||
|
for (var key in o) {
|
||
|
if (has.call(o, key)) {
|
||
|
ret.push(key);
|
||
|
}
|
||
|
}
|
||
|
return ret;
|
||
|
};
|
||
|
|
||
|
var ObjectDefineProperty = function (o, key, desc) {
|
||
|
o[key] = desc.value;
|
||
|
return o;
|
||
|
};
|
||
|
|
||
|
var ObjectFreeze = function (obj) {
|
||
|
return obj;
|
||
|
};
|
||
|
|
||
|
var ObjectGetPrototypeOf = function (obj) {
|
||
|
try {
|
||
|
return Object(obj).constructor.prototype;
|
||
|
}
|
||
|
catch (e) {
|
||
|
return proto;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var ArrayIsArray = function (obj) {
|
||
|
try {
|
||
|
return str.call(obj) === "[object Array]";
|
||
|
}
|
||
|
catch(e) {
|
||
|
return false;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
module.exports = {
|
||
|
isArray: ArrayIsArray,
|
||
|
keys: ObjectKeys,
|
||
|
defineProperty: ObjectDefineProperty,
|
||
|
freeze: ObjectFreeze,
|
||
|
getPrototypeOf: ObjectGetPrototypeOf,
|
||
|
isES5: isES5,
|
||
|
propertyIsWritable: function() {
|
||
|
return true;
|
||
|
}
|
||
|
};
|
||
|
}
|