当前位置: 代码迷 >> JavaScript >> JAVASCRIPT惯用函数集合
  详细解决方案

JAVASCRIPT惯用函数集合

热度:345   发布时间:2013-08-01 15:23:18.0
JAVASCRIPT常用函数集合
1、删除数组某项
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function (from, to) {
    var rest = this.slice((to || from) + 1 || this.length);
    this.length = from < 0 ? this.length + from : from;
    return this.push.apply(this, rest);
};


2、当前时间

function getNow() {
	var date = new Date();
	return date.getFullYear() + "-" + (parseInt(date.getMonth()) + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
}


3、格式化日期
function formater(date) {
	return date.getFullYear() + "-" + (parseInt(date.getMonth()) + 1) + "-" + date.getDate();
}


4、判断是否JSON格式对象
function isJson(obj) {
	return typeof(obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && !obj.length;
}


  相关解决方案