标签:cti isnan 获取 cal null param -- sar isp
1 判断属性 71 -81 var hasOwnProperty = Object.prototype.hasOwnProperty; /** * Check whether the object has the property. * * @param {Object} obj * @param {String} key * @return {Boolean} */ function hasOwn(obj, key) { return hasOwnProperty.call(obj, key); } 2 判断传进来的值是否定义 定义转为字符串 未定义转为空(108 - 118) function _toString(value) { return value == null ? ‘‘ : value.toString(); } 3 转为数字(127-135) function toNumber(value) { if (typeof value !== ‘string‘) { return value; } else { var parsed = Number(value); return isNaN(parsed) ? value : parsed; } } 4 判断是否为纯粹对象 279-284 var toString = Object.prototype.toString; var OBJECT_STRING = ‘[object Object]‘; function isPlainObject(obj) { return toString.call(obj) === OBJECT_STRING; } 5 (是否为数组)293 var isArray = Array.isArray; var isArray = Array.isArray; 6 Define a property.(304-311) function def(obj, key, val, enumerable) { Object.defineProperty(obj, key, { value: val, enumerable: !!enumerable, writable: true, configurable: true }); } 7 获取数组中的元素 (353-359) function indexOf(arr, obj) { var i = arr.length; while (i--) { if (arr[i] === obj) return i; } return -1; } 8 判断是否为对对象的方法 function isObject(obj) { return obj !== null && typeof obj === ‘object‘; } 9 将两个对象合并(267-269) * @param {*} obj * @return {Boolean} function extend(to, from) { var keys = Object.keys(from); var i = keys.length; while (i--) { to[keys[i]] = from[keys[i]]; } return to; } 10 判断两个值是否相等 包含对象相等 389 -393 function looseEqual(a, b) { /* eslint-disable eqeqeq */ return a == b || (isObject(a) && isObject(b) ? JSON.stringify(a) === JSON.stringify(b) : false); /* eslint-enable eqeqeq */ } 11 判断对象中是否含有__proto__ 属性 395 var hasProto = (‘__proto__‘ in {});
标签:cti isnan 获取 cal null param -- sar isp
原文地址:http://www.cnblogs.com/zhujiasheng/p/6507387.html