总结js基础方法


//判断对象上是否有个这个属性 hasPro
return obj != null && hasOwnProperty.call(obj, key);


//判断是不是布尔值 isBoolean
return obj === true || obj === false || toString.call(obj) === '[object Boolean]';


//判断是不是对象 isObject
var type = typeof obj;
return type === 'function' || type === 'object' && !!obj;


//判断是不是为空 isNull
return obj === null;

//判断如果obj是undefined返回true。 isUndefined
return obj === void 0;


//获取某区间的随机数
_.random = function(min, max) {
if (max == null) {
max = min;
min = 0;
}
return min + Math.floor(Math.random() * (max - min + 1));
};


//获取时间
_.now = Date.now || function() {
return new Date().getTime();
};

//判断是不是function
_.isFunction = function(obj) {
return typeof obj == 'function' || false;
};

原文地址:https://www.cnblogs.com/rainheader/p/5254111.html