interface  Date{
addHours(h:number);
addMinutes(m:number);
format(str):string
} interface String{
trim():string;
solrFormat():string;
} interface Array<T> {
clear();
removeByIndex(index:number);
remove(fn:(t:T)=>boolean);
} (function(){ Date.prototype.addHours= function(h:number) {
this.setTime(this.getTime() + (h*60*60*1000));
return this;
} ;
Date.prototype.addMinutes= function(m:number) {
this.setTime(this.getTime() + (m*60*1000));
return this;
} ;
Date.prototype.format=function(fmt:string="yyyy-MM-dd hh:mm:ss"):string {
let date=this;
if(!date){
return date;
}
if (fmt === undefined || fmt === "" || fmt === null) {
fmt = "yyyy-MM-dd hh:mm:ss";
} let o = {
"M+": date.getMonth() + 1, //月份
"d+": date.getDate(), //日
"h+": date.getHours(), //小时
"m+": date.getMinutes(), //分
"s+": date.getSeconds(), //秒
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
for (let k in o)
if (new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
};
if(!String.prototype.trim){
String.prototype.trim=function () {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '')||"";
}
}
String.prototype.solrFormat=function () {
if(!this){
return this;
}
let str= this.replace(/[\(\)\{\}\[\]\^\*&%#$@!<>?=:'"]/g,"");
str=this.replace(/-/,"\\-");
return str.replace(/[\ +]/g,"\\ ")
};
Array.prototype.clear=function () {
this.splice(0,this.length);
}
Array.prototype.removeByIndex= function(index:number) {
this.splice(index,1);
};
Array.prototype.remove= function(fn:(t:any)=>boolean) {
let items = this.filter(fn);
let that=this;
items.forEach(function (item) {
let index = that.indexOf(item);
this.removeByIndex(index);
})
};
})();
d.ts  declare file
declare interface Date{
addHours(h:number);
addMinutes(m:number);
format(str):string
} declare interface String{
trim();
solrFormat():string;
} declare interface Array<T> {
clear();
removeByIndex(index:number);
remove(fn:(t:T)=>boolean);
}

javascript extend的更多相关文章

  1. JavaScript学习笔记(四)——jQuery插件开发与发布

    jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定好用, ...

  2. JavaScript学习总结(四)——jQuery插件开发与发布

    jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定好用, ...

  3. $.extend()的用法【转】

    1.合并多个对象. 这里使用的就是$.extend()的嵌套多个对象的功能. 所谓嵌套多个对象,有点类似于数组的合并的操作. 但是这里是对象.举例说明. 代码如下: <span style=&q ...

  4. jQuery.extend和jQuery.fn.extend的区别?

    jquery 本身 是由 Resig: 莱希格, 一个美国的小伙子小伙伴开发的, 在2005年 prototype发表之后, 在2006年1月发表的, 后来进入mozilla工作, mozilla的j ...

  5. JavaScript学习总结(五)——jQuery插件开发与发布

    jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定好用, ...

  6. jQuery $.extend()使用方法

    $.extend()使用方法总结. jQuery为开发插件提拱了两个方法,各自是: jQuery.fn.extend(object); jQuery.extend(object); jQuery.ex ...

  7. JQuery$.extend()用法

    1.合并多个对象. <span style="font-size:18px;">//用法: jQuery.extend(obj1,obj2,obj3,..) var C ...

  8. javaScript学习总结(二)——jQuery插件的开发

    概要 jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定 ...

  9. jquery 原理

    /* * my-jquery-1.0 *//* * 网上也有很多实现的版本,不过这是我在我自己的理解下写的,加上注释,希望可以解释清楚.*//* * 整个jquery包含在一个匿名函数中,专业点叫闭包 ...

随机推荐

  1. consul集群搭建,配合nginx完成服务动态发现和健康检查

    1.概述 1.1 介绍 consul是一个服务发现和配置共享的服务软件,结合nginx的主动健康检查模块nginx_upstream_check_module和服务发现模块nginx-upsync-m ...

  2. 串口通信DMA中断

    这是以前学32的时候写的,那时候学了32之后感觉32真是太强大了,比51强的没影.关于dma网上有许多的资料,亲们搜搜,这里只贴代码了,其实我也想详详细细地叙述一番,但是自己本身打字就慢,还有好多事情 ...

  3. 查看历史命令 history

    生产上有文件被清空了,想查查是谁操作的? 通过history查看历史命令: $history |more 也可以通过文件查看历史命令: $vi ~/.bash_history 只显示历史命令,像查一查 ...

  4. Android 下拉刷新上拉加载PullToRefresh

    https://github.com/823546371/PullToRefresh http://www.jianshu.com/p/0f5d0991efdc

  5. Bluedroid协议栈BTU线程处理HCI数据流程分析

    在蓝牙enable的过程中会进行多个线程的创建以及将线程与队列进行绑定的工作.该篇文章主要分析一下处理hci数据这个 线程. void BTU_StartUp(void) { ... btu_bta_ ...

  6. python 生成器按指定大小读取文件

    #!/usr/bin/env python import osimport sys def read_file(fpath): Block_Size = 1024 with open(fpath,&q ...

  7. JavaScript中call,apply,bind方法的区别

    call,apply,bind方法一般用来指定this的环境. var a = { user:"hahaha", fn:function(){ console.log(this.u ...

  8. 《无所不能的JavaScript编程系列:setTimeout 简笔》

    前言:问题引出 JavaScript中会经常用到setTimeout来推迟一个函数的执行,如: setTimeout(function(){alert("Hello World") ...

  9. python中类中属性和方法的具体定义方法和使用

    1. Python中类中特性分成属性和方法 属性和方法都分为私有和公有的,私有的只可以在本类中使用外部是无法访问的 2. 定义属性(成员变量)的语法格式(公有属性/私有属性) class 类名: de ...

  10. 带WIFI模块布局布线要点。

    带WIFI模块布局布线要求: 1: RF底部不能铺铜要挖空不能有GND否则RF信号会被耦合掉从而无法发送出去. 2:WIFI模块下方不能打孔尽量不走线不打孔避开其他信号穿过下方,要整体的铺铜 3:连接 ...