js简单函数封装
//每index个字符插入一个str字符串
String.prototype.insertStrPerIndex =function(index,str){
if(this.length>index&&index>0){
var arr = new Array();
var num = parseInt(this.length/index);
console.log(num);
for(var i=0;i<=num;i++){
var firstval =i*index;
if(firstval<this.length){
arr.push(this.substr(firstval,index));
}
}
return arr.join(str);
}else{
return this.toString();
}
}
//去掉字符串两端的空白
String.prototype.trim = function() {
return this.replace(/(^\s+)|(\s+$)/g, "");
}
//构建Stringbuffer
function StringBuffer(){
this.content = new Array;
}
StringBuffer.prototype.append = function( str ){
this.content.push( str );
}
StringBuffer.prototype.toString = function(){
return this.content.join("");
}
//去掉所有的空格、table
String.prototype.trimAll = function() {
return this.replace(/\s/g,"")
}
//重写replaceAll
String.prototype.replaceAll =function(oldWord,newWord){
var res =this;
var mid ="";
while((mid=res.replace(oldWord,newWord))!=res){
res =mid;
}
return res;
}
//判断是否是中文
js简单函数封装的更多相关文章
- JS 对象封装的常用方式
JS是一门面向对象语言,其对象是用prototype属性来模拟的,下面,来看看如何封装JS对象. 常规封装 function Person (name,age,sex){ this.name = na ...
- js类封装
将js方法封装成类,好处就是团队开发中避免命名冲突,部分类整理代码如下: function LocalStorageHelper() { //检测浏览器是否支持localStorage this.ch ...
- 【Node.js 自己封装的库 http_parse, libuv】
[Node.js 自己封装的库 http_parse, libuv] Node.js 介绍:一个网络框架,更多:http://www.oschina.net/p/nodejs 官网:http://no ...
- main.js中封装全局登录函数
1. 在 main.js 中封装全局登录函数 通过 vue 对象的原型扩展,可以扩展一个函数,这样这个函数就可以在每一个界面通过类似指向对象的方式,去访问这个函数. 如下是 main.js 扩展的函数 ...
- Node.js模块封装及使用
Node.js中也有一些功能的封装,类似C#的类库,封装成模块这样方便使用,安装之后用require()就能引入调用. 一.Node.js模块封装 1.创建一个名为censorify的文件夹 2.在c ...
- 基于js原生封装的点击显示完整文字
基于js原生封装的点击显示完整文字 (function(window) { var inner = ''; var showCont_s = function(ele) { this.init.app ...
- react request.js 函数封装
1.request.js 函数封装 import { Toast } from 'antd-mobile'; import axios from 'axios'; import store from ...
- 使用jq把js代码封装一个自己的插件
为什么要把js功能封装成插件呢?我觉得有以下几点吧 1.最基本的原因就是便于代码复用. 2.便于维护和管理. 3.提升自身的能力. 4.避免各个相同功能组件的干扰,以及一些作用域会相互影响的问题. j ...
- 常用js方法封装
常用js方法封装 var myJs = { /* * 格式化日期 * @param dt 日期对象 * @returns {string} 返回值是格式化的字符串日期 */ getDates: fun ...
随机推荐
- 移动web——bootstrap模板
基本概念 1.bootstrap就是在媒体查询技术出现以后才开始出现的 2.此技术使响应式开发变得十分轻松,最大特点就是栅格系统(什么设备上如何显示)以及响应式工具(是否可见) 基本模板 <!D ...
- Ajax——php基础知识(二)
header header('content-type:text/html; charset= utf-8');//设置编码格式为:utf-8 header('location:http://www. ...
- dotnetnuke 添加用户属性 Profile
if (DotNetNuke.Entities.Profile.ProfileController.GetPropertyDefinitionByName(this.PortalId, "Q ...
- 6、scala Map和Tuple
1. 创建Map 2.访问Map元素 3.修改Map元素的值 4.遍历Map 5.SortedMap和LinkedHashMap 6.Map的元素类型Tuple 1. 创建Map 创建不可变的Ma ...
- javascript的严格模式:use strict
ECMAscript 5添加的运行模式,禁止一些非标准.不安全的操作. <script> "use strict"; console.log("这是严格模式. ...
- scp: /xxxx: not a regular file
问题描述 scp root@10.2.1.92:/home /home/wangju/databakroot@10.2.1.92's password: xxxxscp: /home: not a r ...
- 如何在mac里面,把xcode代码同步到 tfs 的 git库(新git库)
克隆篇请参考:http://www.cnblogs.com/IWings/p/6744895.html 在mac安装visual studio code https://code.visualstud ...
- 《Mysql - 到底可不可以使用 Join ?》
一:Join 的问题? - 在实际生产中,使用 join 一般会集中在以下两类: - DBA 不让使用 Join ,使用 Join 会有什么问题呢? - 如果有两个大小不同的表做 join,应该用哪个 ...
- API 接口监控产品全新改版,免费开放全部功能
作为 EOLINKER 研发管理体系的重要一环,EOLINKER 接口监控即 AMT 产品将在 3月4日 迎来全新变化,AMT 产品将正式命名为 EOLINKER-API Beacon --API-烽 ...
- kernel memory code learn
mem alloc page Noticeble: 1. there are two kind of page: virtual page, physical page. 2. the page st ...