Namespace technique in JavaScript having issues in JSLint

I read an article regarding the various ways to namespace in JavaScript. I quite liked the look of the last one but JSLint thinks otherwise. I know JSLint can be overzealous but is there a way to make this technique play nice with it?

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

Try to use call instead of apply . apply is defined with exactly two parameters (where second one is array of arguments) and call really requires only one parameter (namespace) and has list of optional arguments.

链接地址: http://www.djcxy.com/p/17046.html

上一篇: 使用名称空间代替类

下一篇: JavaScript中的命名空间技术在JSLint中存在问题