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) { //检查是否
随机推荐
- 用Python制作在地图上模拟瘟疫扩散的Gif图
- vuejs2.0子组件改变父组件的数据实例
- Python批量按比例缩小图片脚本分享
- JS图片延迟加载插件LazyImgv1.0用法分析【附demo源码下载】
- Mysql如何避免全表扫描的方法
- JSP由浅入深(11)—— 标记库
- JavaScript判断浏览器及其版本信息
- Node.js实现兼容IE789的文件上传进度条
- jQuery UI设置固定日期选择特效代码分享
- JavaScript ( (__ = !$ + $)[+$] + ({} + $)[_/_] +({} + $)[_/_] )
- C#获取每个年,月,周的起始日期和结束日期的方法
- apache中封IP的实现方法
- 深入解析C++编程中的纯虚函数和抽象类
- Android 设置Edittext获取焦点并弹出软键盘
- 多重條件組合查詢(一)
- Angular之toDoList的实现代码示例
- PHP封装的数据库模型Model类完整示例【基于PDO】
- golang顺时针打印矩阵的方法示例
- Laravel框架生命周期与原理分析
- 通过Java压缩JavaScript代码实例分享