Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.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 JSLint的修复;意外';这个'&引用;错误?_Javascript_This_Jslint - Fatal编程技术网

Javascript JSLint的修复;意外';这个'&引用;错误?

Javascript JSLint的修复;意外';这个'&引用;错误?,javascript,this,jslint,Javascript,This,Jslint,我试图将以下代码变成,但遇到以下两个错误: 期望看到一条语句,而不是看到一个块 及 意外的“这个” 我应该对我的代码进行哪些更改以使JSLint满意 var pvAccess = {}; pvAccess.Func = function () { "use strict"; function AccessPV(name, rValue, wValue) { var url = '/goform/ReadWrite', dat

我试图将以下代码变成,但遇到以下两个错误:

期望看到一条语句,而不是看到一个块

意外的“这个”

我应该对我的代码进行哪些更改以使JSLint满意

var pvAccess =  {};

pvAccess.Func = function () {
    "use strict";

    function AccessPV(name, rValue, wValue) {

        var url = '/goform/ReadWrite',    
            data = 'redirect=/response.asp&variable=' + escape(name),
            xmlHttp = null,
            wValue = null;

        if (rValue !== null && rValue !== "") {    
            data += '&value=' + escape(rValue);
            data += "&write=1";
        } else {
            data += '&value=none';
            data += "&read = 1";
        }

        try {
            // Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
            xmlHttp = new XMLHttpRequest();
        } catch (e) {
            try {
                // MS Internet Explorer (ab v6)
                xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e2) {
                try {
                    // MS Internet Explorer (ab v5)
                    xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e3) {
                    xmlHttp  = null;
                }
            }
        }

        if (xmlHttp) {    
            xmlHttp.open('POST', url, 1);
            xmlHttp.onreadystatechange = function () {

                if (xmlHttp.readyState === 4) {
                    if (wValue !== null) {
                        wValue[3] = xmlHttp.responseText;
                        wValue[3] = wValue[3].replace("<!-- B&R ASP Webserver -->", "");
                        // value attribute of node    
                        wValue.value = wValue[3];
                        return wValue;
                    }
                }
            };

            xmlHttp.send(data);
        }
    }

// public
    {    
        this.WritePV = function (name, value) { AccessPV(name, value); }
        this.ReadPV = function (name, wValue) { return AccessPV(name, null, wValue); }
    }
}

pvAccess = new pvAccess.Func();
var pvAccess={};
pvAccess.Func=函数(){
“严格使用”;
函数AccessPV(名称、右值、W值){
var url='/goform/ReadWrite',
data='redirect=/response.asp&variable='+escape(名称),
xmlHttp=null,
wValue=null;
如果(右值!==null&&右值!==“”){
数据+='&值='+转义(右值);
数据+=“&write=1”;
}否则{
数据+='&值=无';
数据+=“&read=1”;
}
试一试{
//Mozilla、Opera、Safari sowie Internet Explorer(ab v7)
xmlHttp=新的XMLHttpRequest();
}捕获(e){
试一试{
//MS Internet Explorer(ab v6)
xmlHttp=新的ActiveXObject(“Microsoft.xmlHttp”);
}渔获物(e2){
试一试{
//MS Internet Explorer(ab v5)
xmlHttp=新的ActiveXObject(“Msxml2.xmlHttp”);
}渔获物(e3){
xmlHttp=null;
}
}
}
if(xmlHttp){
open('POST',url,1);
xmlHttp.onreadystatechange=函数(){
if(xmlHttp.readyState==4){
如果(wValue!==null){
wValue[3]=xmlHttp.responseText;
wValue[3]=wValue[3]。替换(“,”);
//节点的值属性
wValue.value=wValue[3];
返回wValue;
}
}
};
发送(数据);
}
}
//公开的
{    
this.WritePV=函数(名称,值){AccessPV(名称,值);}
this.ReadPV=函数(name,wValue){return AccessPV(name,null,wValue);}
}
}
pvAccess=new pvAccess.Func();

我能看到可能导致这种情况的两件事是:

  • 在公共方法周围有不必要的
    {}
    s。这可能是导致预期语句错误的原因
  • 您的公共方法是赋值语句,而不仅仅是函数,因此您应该在函数定义后以分号结尾。如果没有这个,lint将它作为一行代码读取(
    this.WritePV=function{…}this.ReadPV
    ),因此出现了“意外的this”
  • 因此,您需要更改公共方法,使其如下所示:

    // public
        this.WritePV = function (name, value) { AccessPV(name, value); };
    
        this.ReadPV = function (name, wValue) { return AccessPV(name, null, wValue); };
    
    ^^^

    这就是导致错误的原因。拆下那些支架,它就会自行修复。它还希望您使用分号

        this.WritePV = function (name, value) { AccessPV(name, value); };
    
        this.ReadPV = function (name, wValue) { return AccessPV(name, null, wValue); };
    

    为什么不告诉我们它在哪几行给了我们错误。{this.WritePV=function(name,value){AccessPV(name,value);}this.ReadPV=function(name,wValue){return AccessPV(name,null,wValue);}}关于“意外的
    this
    ”:JSLint现在提供了一个选项来抑制这种抱怨。请注意这个类似的问题。非常感谢,这很有效:)他现在唯一抱怨的是:意外的“pvAccess”。对于列var pvAccess=new pvAccess.Func();同样,在函数定义的末尾需要一个分号
        this.WritePV = function (name, value) { AccessPV(name, value); };
    
        this.ReadPV = function (name, wValue) { return AccessPV(name, null, wValue); };