屹砾技术博客,记录生活点滴。 Email/QQ/Skype/MSN/GTalk: eli.wuhan@gmail.com
posted on 2008-06-27 15:26 屹砾 阅读(1095) 评论(5) 编辑 收藏 所属分类: Html / JS / PHP
function(a, b)就是这个str, arr 回复 更多评论
@haix a, b 的值是正则表达式的值, a=\{(\w+)\} b=(\w+) 但是不知道为什么这里的a, b 就代表正则表达式的这两个值呢? a是\{(\w+)\}匹配的值 b是(\w+)匹配的值 回复 更多评论
因为这个函数是回调函数- -! google了解下好了,啥是回调函数 回复 更多评论
ECMAScript v3 specifies that the replacement argument to replace( ) may be a function instead of a string. In this case, the function is invoked for each match, and the string it returns is used as the replacement text. The first argument to the function is the string that matches the pattern. The next arguments are the strings that match any parenthesized subexpressions within the pattern; there may be zero or more of these arguments. The next argument is an integer that specifies the position within string at which the match occurred, and the final argument to the replacement function is string itself. 试图帮你找了一下答案,正如上文:在ECMAScript语言说明中表示,replace()方法中的第二个参数(替换参数)可以用一个函数代替字符串,正如楼主所用的这样。在这种情况下,函数会被每个匹配调用,并且返回的字符串就是使用了替换文的。第一个参数就是符合整个正则表达的字符串,接下来的参数是正则中使用括号的子表达式,当然可能会有很多。接下来的参数就是一个表明了在原字符串中正则匹配发生的位置的整数,这个函数的最后一个参数则是被替换的字符串本身。回头看看楼主的问题,就不再是问题了吧,可以试着再多加几个参数,输出看看,是否符合上面的解释,答案是肯定的。:)另外还想说两句,知之为知之,不知为不知,是知也。 回复 更多评论
@pentiumao 很清晰,很透彻,谢谢! 知之为知之,不知为不知,是知也。 知道就是知道,不知道就是不知道,这才是智慧(睿智)的。 回复 更多评论
Powered by: BlogJava Copyright © 屹砾