Prototype RegExp对象 学习
RegExp.prototype.match = RegExp.prototype.test;
RegExp.escape = function(str) {
return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
};
就一个escape方法,就是把那几个特殊字符转义一下。
还有就是match方法是test方法的别名。
看一个例子:
var str=RegExp.escape("+.[]$://!");
document.writeln(str) //==> "\+\.\[\]\$\:\/\/\!"
相关推荐
-
Prototype RegExp对象 学习
复制代码 代码如下: RegExp.prototype.match = RegExp.prototype.test; RegExp.escape = function(str) { return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1'); }; 就一个escape方法,就是把那几个特殊字符转义一下. 还有就是match方法是test方法的别名. 看一个例子: var str=RegExp.escape("+.[]$://!
-
Prototype Enumerable对象 学习第1/2页
Enumerable provides a large set of useful methods for enumerations, that is, objects that act as collections of values. It is a cornerstone of Prototype. Enumerable is what we like to call a module: a consistent set of methods intended not for indepe
-
Prototype Selector对象学习
复制代码 代码如下: function $$() { return Selector.findChildElements(document, $A(arguments)); } 这个类可以分成三个部分:第一个部分就是根据不同的浏览器,判断使用什么DOM操作方法.其中操作IE就是用普通的getElementBy* 系列方法:FF是document.evaluate:Opera和Safari是selectorsAPI.第二部分是对外提供的基本函数,像findElements,match等,Eleme
-
Prototype String对象 学习
复制代码 代码如下: //String对象的静态方法 Object.extend(String, { interpret: function(value) { return value == null ? '' : String(value); }, specialChar: { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '\\': '\\\\' } }); Object.extend(String.prot
-
Prototype ObjectRange对象学习
Ranges represent an interval of values. The value type just needs to be "compatible," that is, to implement a succ method letting us step from one value to the next (its successor). Prototype provides such a method for Number and String, but you
-
Prototype Class对象学习
复制代码 代码如下: /* Based on Alex Arnell's inheritance implementation. */ var Class = (function() { //临时存储parent的prototype function subclass() {}; //创建类的方法 function create() { var parent = null, properties = $A(arguments); //检查新建一个类时,是否指定了一个父对象 //如
-
Prototype Object对象 学习
Object is used by Prototype as a namespace; that is, it just keeps a few new methods together, which are intended for namespaced access (i.e. starting with "Object."). 上面说的namespace个人理解就相当于C#中的静态类,提供工具函数的意思,和C#中的namespace应该不是一个概念.因为C#中的命名空间后面不会直
-
Prototype Hash对象 学习
复制代码 代码如下: //Hash对象的工具函数 function $H(object) { return new Hash(object); }; var Hash = Class.create(Enumerable, (function() { //初始化,创建一个新的Hash对象 function initialize(object) { this._object = Object.isHash(object) ? object.toObject() : Object.clone(obje
-
Prototype Array对象 学习
复制代码 代码如下: Array.from = $A; (function() { //Array原型的引用 var arrayProto = Array.prototype, slice = arrayProto.slice, //JS 1.6里面会有原生的forEach方法 _each = arrayProto.forEach; // use native browser JS 1.6 implementation if available function each(it
-
Prototype Template对象 学习
复制代码 代码如下: var Template = Class.create({ //初始化方法 initialize: function(template, pattern) { this.template = template.toString(); this.pattern = pattern || Template.Pattern; }, //格式化方法,如果从java的角度来说,其实叫format更好 :) evaluate: function(object) { //检查是否
随机推荐
- Java 位图法排序的使用方法
- iOS中实现图片自适应拉伸效果的方法
- ios UITableView实现无数据加载占位图片
- JavaScript 新手24条实用建议[TUTS+]
- 详解C++设计模式编程中对访问者模式的运用
- SQL执行步骤的具体分析
- 网页设计布局基础第1/4页
- sed或awk处理文件最后一行的实现方法
- C语言实现去除字符串中空格的简单实例
- 一看就懂:jsonp详解
- JavaScript数据结构与算法之栈与队列
- top.location.href 没有权限 解决方法
- 试用google search的Ajax api
- 为Nginx添加SPDY功能
- Java连接并操作Sedna XML数据库的方法
- 浅谈hibernate中多表映射关系配置
- 基于策略的多路径广域网
- Java实现的模糊匹配某文件夹下的文件并删除功能示例
- 美团DB数据同步到数据仓库的架构与实践
- python+selenium实现简历自动刷新的示例代码