String.method('deentityify', function ( ) {// The entity table. It maps entity names to
// characters. var entity = {
quot: '"',
lt: '<',
gt: '>'
};// Return the deentityify method. return function ( ) {// This is the deentityify method. It calls the string
// replace method, looking for substrings that start
// with '&' and end with ';'. If the characters in
// between are in the entity table, then replace the
// entity with the character from the table. It uses
// a regular expression (Chapter 7). return this.replace(/&([^&;]+);/g,
function (a, b) {
var r = entity[b];
return typeof r === 'string' ? r : a;
}
);
};
}( ));
====================================
document.writeln(
'<">'.deentityify( )); // <">
====================================函数调用的时候,内部的函数参数是怎么传递的啊? 比如这里的 function (a,b) a,b的值是指什么?
// characters. var entity = {
quot: '"',
lt: '<',
gt: '>'
};// Return the deentityify method. return function ( ) {// This is the deentityify method. It calls the string
// replace method, looking for substrings that start
// with '&' and end with ';'. If the characters in
// between are in the entity table, then replace the
// entity with the character from the table. It uses
// a regular expression (Chapter 7). return this.replace(/&([^&;]+);/g,
function (a, b) {
var r = entity[b];
return typeof r === 'string' ? r : a;
}
);
};
}( ));
====================================
document.writeln(
'<">'.deentityify( )); // <">
====================================函数调用的时候,内部的函数参数是怎么传递的啊? 比如这里的 function (a,b) a,b的值是指什么?
解决方案 »
- 在button的onclick事件的方法中是否可以插入Java数据作为参数?
- 有没有好用的英文web论坛?
- 如何在目录树里面实现右键菜单??
- 关于阿信的xml tree在lunix服务器下的问题,阿信也进来看看吧
- c# 中javascript 的问题
- 将画面表格导出为Excel后,出现拒绝访问的JS错误?如何处理?如有办法,不够在加
- IE窗口最小化以后,如有新增贴子,IE窗口闪烁,如何实现?
- 如何去掉这种提示?
- 简单的语法问题,请问如何跳出for循环
- 关于网页在客户端自动下传的问题?
- 关于jsp用(jsp:forward)转到下一页面的问题
- 探寻下大家的选择关于jQuery(JS、Ajax)&Flex
function (a, b) {
var r = entity[b];
return typeof r === 'string' ? r : a;
}
);a是/&([^&;]+);/全部匹配的内容, b是括号中获取的内容,这和是否闭包没有关系,里面的entity[]调用才算是闭包的范畴!< 当前匹配是这个的话,那么
a = '<';
r = 'lt';
上面少写了一个分号,应该是//< 当前匹配是这个的话,那么
a = '<';
r = 'lt';