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

时间:2012-03-05 01:16:08

标签: javascript namespaces jslint

我读了一篇关于namespace in JavaScript的各种方法的文章。我非常喜欢最后一个的外观,但JSLint不这么认为。我知道JSLint可能过于热心,但有没有办法让这种技术很好玩呢?

var Something = {};

(function () {
    "use strict";

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

}.apply(Something));

2 个答案:

答案 0 :(得分:3)

请改为尝试:

var Something = {};

(function (something) {
    "use strict";

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

}(Something));

答案 1 :(得分:-2)

尝试使用call代替applyapply定义了两个参数(其中第二个是参数数组),call实际上只需要一个参数(命名空间),并且包含可选参数列表。