简体   繁体   English

Safari显示JS错误,但Chrome没有显示

[英]Safari showing JS error, but Chrome doesn't

I'm quite new to JS. 我是JS的新手。 I've been developing a couple of JS function. 我一直在开发一些JS函数。 They work in Chrome. 他们可以在Chrome中使用。 Yesterday I tried it in Safari and it's spitting out errors. 昨天我在Safari中尝试过,它吐出了错误。

The function: 功能:

Request.SetForm = function (form, ruleset = [], messageset = null, focus = null, special = false, ignore = false) {

// Code here

}

I'm calling it like: 我这样称呼它:

var $validator = Request.SetForm(arguments here);

Now Safari says: 现在Safari表示:

ReferenceError: Can't find variable: Request ReferenceError:找不到变量:请求

Well as I said, Chrome doesn't say anything and it works fine. 就像我说的,Chrome没说什么,它工作正常。 What's wrong here? 怎么了

Don't forget to declare the Request before using. 使用前不要忘记声明请求。 use 采用

var Request = {};

Then use 然后使用

Request.method = function(){}

Because some older versions can't resolve a variable if not declared ( Normally the issue happen when we use in use strict mode. 由于某些较旧的版本如果未声明则无法解析变量(通常,在use strict模式下use strict时会发生此问题。

Or else, Request may be a keyword or built in method in the version of safari you are using. 否则,Request可能是您使用的safari版本中的关键字或内置方法。 So just change the name. 因此,只需更改名称即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM