0
作为以下代码,我的问题是:
in testFunction,我怎样才能调用函数删除?
在删除我如何可以调用testFunction?
在删除,我怎么能打电话添加?
在JavaScript对象字面量中,如何引用具有相同级别或更高级别的函数?
十分感谢
var stringhelper={
testFunction:function(){},
//deal with text such as:
//"alignleft red bold header2"
classValue:{
//test whether classValue has className in it
has:function(classValue,className){
var regex=new RegExp("(^|\\s+)"+className+"(\\s+|$)");
return regex.test(classValue);
},
remove:function(classValue,className){
return classValue.replace(className,"").replace(/\s+/g," ").replace(/^\s+|\s+$/g,"");
},
add:function(classValue,className){
if(/^\s+$/.test(classValue)){
return className;
}
if(!this.has(classValue,className)){
return classValue+" "+className;
}
}
}
};
为什么不'stringhelper.classValue.remove()'?这样,函数的别名不会混淆“this”引用。 – kangax 2009-10-11 07:19:09