javascript extend
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的更多相关文章
- JavaScript学习笔记(四)——jQuery插件开发与发布
jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定好用, ...
- JavaScript学习总结(四)——jQuery插件开发与发布
jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定好用, ...
- $.extend()的用法【转】
1.合并多个对象. 这里使用的就是$.extend()的嵌套多个对象的功能. 所谓嵌套多个对象,有点类似于数组的合并的操作. 但是这里是对象.举例说明. 代码如下: <span style=&q ...
- jQuery.extend和jQuery.fn.extend的区别?
jquery 本身 是由 Resig: 莱希格, 一个美国的小伙子小伙伴开发的, 在2005年 prototype发表之后, 在2006年1月发表的, 后来进入mozilla工作, mozilla的j ...
- JavaScript学习总结(五)——jQuery插件开发与发布
jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定好用, ...
- jQuery $.extend()使用方法
$.extend()使用方法总结. jQuery为开发插件提拱了两个方法,各自是: jQuery.fn.extend(object); jQuery.extend(object); jQuery.ex ...
- JQuery$.extend()用法
1.合并多个对象. <span style="font-size:18px;">//用法: jQuery.extend(obj1,obj2,obj3,..) var C ...
- javaScript学习总结(二)——jQuery插件的开发
概要 jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定 ...
- jquery 原理
/* * my-jquery-1.0 *//* * 网上也有很多实现的版本,不过这是我在我自己的理解下写的,加上注释,希望可以解释清楚.*//* * 整个jquery包含在一个匿名函数中,专业点叫闭包 ...
随机推荐
- C语言程序设计II—第一周教学
第一周教学总结(25/2-3/3) 教学内容 开学谈心 测验数据类型.运算符与表达式的自学情况,并讲解测验题目 第七章 数组 7.1 一维数组 课前准备 在蓝墨云发布资源:回顾数据类型与表达式测试活动 ...
- php 操作时间、日期类函数
<?php // time() echo "time(): ",time(); echo "\n"; // strtotime() echo " ...
- BiCMOS技术
BiCMOS技术 编辑 本词条由“科普中国”百科科学词条编写与应用工作项目 审核 . 把双极型晶体管(BJT)和CMOS器件同时集成在同一块芯片上的新型的工艺技术,它集中了上述单.双极型器件的优点,两 ...
- 报错Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
解决方法:import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'输入1:显示所有信息 2:只显示warning和erro ...
- 大数据入门第二十四天——SparkStreaming(一)入门与示例
一.概述 1.什么是spark streaming Spark Streaming is an extension of the core Spark API that enables scalabl ...
- python利用beautifulSoup写爬虫
python BeautifulSoup模块的安装 安装包下载地址:http://www.crummy.com/software/BeautifulSoup/#Download 文档:http://w ...
- WPF Good UI
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.co ...
- EZ 2017 01 07 t
这名字诡异(然而就是这样) 这次主要是yekehe和yu‘ao都来了,所以很开心的讨论(上了200). 但是,yu’ao dalao又AK了!(666666) 不过总体难度也不高,主要是T3没思路. ...
- Gitlab+Jenkins学习之路(十四)之自动化脚本部署实践
目录 一.环境说明和准备 1.环境说明 2.服务器准备工作 二.发布脚本编写 1.自动化部署流程设计 2.自动化部署脚本编写 三.发布测试 1.开发机和github添加ssh信任 2.克隆项目到开发机 ...
- idea git pull项目到本地时容易出现的问题
有时候pull到本地,出了各种错误,其实是因为搞来搞去的,容易出问题,所以最好的方法是拿原有打包好的整个稳定能跑的项目环境, 先git add,然后vcs重置head为hard,然后再pull,一般就 ...