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) { //检查是否
随机推荐
- Lua中string.lower()使用指南
- react.js使用webpack搭配环境的入门教程
- JavaScript SHA-256加密算法详细代码
- PHP中PDO的错误处理
- PHP判断手机是IOS还是Android
- 深入理解Android中Scroller的滚动原理
- 网页中英文混排行高不等问题的解决方法
- jquery中$each()方法的使用指南
- jQuery选择器用法实例详解
- javascript自动切换焦点控制效果完整实例
- C#生成不重复随机数列表实例
- Android自定义控件之继承ViewGroup创建新容器
- Spring MVC的文件上传和下载以及拦截器的使用实例
- C和C++ const的声明差异
- GridView自定义分页的四种存储过程
- Yii框架登录流程分析
- 一个程序下载的管理程序(四)
- 路由器参数介绍
- python并发2之使用asyncio处理并发
- PHP实现分布式memcache设置web集群session同步的方法
