Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript对象文本中,如何引用具有相同级别或更高级别的函数?_Javascript_Json_Object - Fatal编程技术网

在javascript对象文本中,如何引用具有相同级别或更高级别的函数?

在javascript对象文本中,如何引用具有相同级别或更高级别的函数?,javascript,json,object,Javascript,Json,Object,作为以下代码,我的问题是: 在testFunction中,如何调用函数remove? 在remove中如何调用testFunction? 在删除中,如何调用添加? 非常感谢 var stringhelper={ testFunction:function(){}, //deal with text such as: //"alignleft red bold header2" classValue:{ //test whether classValue has className in

作为以下代码,我的问题是:
在testFunction中,如何调用函数remove?
在remove中如何调用testFunction?
在删除中,如何调用添加?

非常感谢

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;    
        }

    }
}
})

要从
testFunction()
访问
remove()
,您可以执行以下操作:

this.classValue.remove();
换个方向我想你得用

stringhelper.testFunction();

因为您没有包含函数或父对象的变量
对象(可以在闭包中使用)。

为什么不
stringhelper.classValue.remove()
?这样,函数的别名就不会打乱
这个
引用。