var str=' <div class="{0}">{1}</div>'
var args=['saber','xq']
str=str.replace(/\{(\d+)\}/g, function(m, i){
return args[i];
})
第二个参数是个方法对象,怎么解释?
引用ECMAScript v3 规定,replace() 方法的参数 replacement 可以是函数而不是字符串。在这种情况下,每个匹配都调用该函数,它返回的字符串将作为替换文本使用。该函数的第一个参数是匹配模式的字符串。接下来的参数是与 ...
- 00:33
- 浏览 (364)
- 评论 (0)
- 分类: JS&ajax
- 发布在 javascript研究小组 圈子
首先贴出prototype.js实现继承的代码:
Object.extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
很明显,这里把source的所有属性copy到destination下,即destination继承source,由于只是简单的属性copy,所以写代码的时候要注意调用Object.extend的顺序,否则无法实现overridi ...
/**
* 工厂方法:
* 存在问题:重复创建对象eat
*/
function CreatePeople(name){
var people=new Object();
people.name=name;
people.eat=function(){
alert(this.name+' is eating !!')
};
return people;
}
/**
* 构造函数法:
* 存在问题:重复创建对象eat
* 使用new 来创建对象,如:var p=new People('saber')
* 在执行第一句代码 ...
代码主要参考ext 2.0的example ,这里加上自己的注释,包括某些参数的含义. 使用ext2.0创建表格很简单: 第一:准备表头,使用Ext.grid.ColumnModel 第二:准备数据,使用Ext.data.Store 第三:创建表格,使用Ext.grid.GridPanel,同时把以上的表头和数据放进去。 Ext.onReady(function() {
/**
* 首先是创建表格的ColumnModel,即定义grid的各个列:
* Ext.grid.ColumnModel([{
* id: 列的唯一标识,可以用于 ...
区别:setTimeout(表达式,延时时间);//只执行一次,无周期
setInterval(表达式,交互时间);//周期='交互时间'
停止:
主要是利用
window.clearInterval(intervalID);
window.clearTimeout(timeoutID);
<SCRIPT>
var intervalID=0;
function f_start(){
intervalID=window.setInterval("f_add()",500);
}
function f_add(){
...
javascript获取屏幕位置 网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽: document.body.offsetWidth (包括边线的宽)网页可见区域高: document.body.offsetHeight (包括边线的高)网页正文全文宽: document.body.scrollWidth网页正文全文高: document.body.scrollHeight网页被卷去的高: document.body.scrollTop网页被卷去的左: document.body.scr ...
<script language="javascript">window.onbeforeunload = function(){var n = window.event.screenX - window.screenLeft;var b = n > document.documentElement.scrollWidth-20;if(b && window.event.clientY < 0 || window.event.altKey){ postTime(); window.event.returnValue ...
- 浏览: 8651 次
- 性别:

- 来自: 龙黄

- 详细资料
搜索本博客
我的相册
IMG_0479
共 8 张
共 8 张
最近加入圈子
最新评论
-
Velocity脚本摘要
总结得不错~~ 谢谢!!
-- by xinshaoye -
[zz]十分钟让你看懂中国经 ...
深入浅出!!
-- by wangxinqn -
Velocity脚本摘要
判断空:#if($var) 就可以了。
-- by sg552






评论排行榜