JavaScript中的命名空间技术在JSLint中存在问题

Namespace technique in JavaScript having issues in JSLint

本文关键字:JSLint 存在 问题 技术 命名空间 JavaScript      更新时间:2023-09-26

我读了一篇关于JavaScript中命名空间的各种方法的文章。我很喜欢上一个的外观,但JSLint不这么认为。我知道JSLint可能过于热情,但有没有办法让这种技术发挥得很好?

var Something = {};
(function () {
    "use strict";
    this.helloWorld = function () {
        var greeting = "Hello World!";
    };
}.apply(Something));

试试这个:

var Something = {};
(function (something) {
    "use strict";
    something.helloWorld = function () {
        var greeting = "Hello World!";
    };
}(Something));

尝试使用call而不是applyapply只定义了两个参数(其中第二个参数是参数数组),而call实际上只需要一个参数(名称空间),并且具有可选参数列表。