六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 29|回复: 0

extjs源码分析-013(String扩展)

[复制链接]

升级  22.33%

75

主题

75

主题

75

主题

举人

Rank: 3Rank: 3

积分
267
 楼主| 发表于 2013-1-29 09:30:18 | 显示全部楼层 |阅读模式
//字符串替换/*var cls = 'my-class', text = 'Some text';var s = String.format('<div class="{0}">{1}</div>', cls, text);*/Ext.applyIf(String, {    format : function(format){        var args = Ext.toArray(arguments, 1);        return format.replace(/\{(\d+)\}/g, function(m, i){            return args[i];        });    },    //对字符串中的|\\进行转义输出    escape : function(string) {        return string.replace(/('|\\)/g, "\\$1");    },    //在字符串val左边插入size-val.length个指定字符串ch,如果ch未定义则默认为" "    leftPad : function (val, size, ch) {        var result = String(val);        if(!ch) {            ch = " ";        }        while (result.length < size) {            result = ch + result;        }        return result;    },})//俩个值切换,调用方式:sort = sort.toggle('ASC', 'DESC');    String.prototype.toggle = function(value, other){     return this == value ? other : value;    };    //去除字符串的空格 调用方式:var s = '  foo bar  ';_s = s.trim();    String.prototype.trim = function(){      var re = /^\s+|\s+$/g;      return function(){ return this.replace(re, ""); };    }()
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表