最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JSHint Backbone not defined in CodeKit - Stack Overflow

programmeradmin7浏览0评论

A small test app is set up like this:

init.js:

//@codekit-prepend "vendor/jquery-1.7.2.js"
//@codekit-prepend "vendor/underscore.js"
//@codekit-prepend "vendor/backbone.js"

// Setup namespace for the app
window.app = window.app || {};

//@codekit-append "models/Ride.js"

Ride.js:

(function() {
    window.app.Ride = Backbone.Model.extend({

        initialize: function() {
            console.log("Ride initialized");
        }
    });
})();

CodeKit's JSHint check reports that both Backbone and console are not defined. What am I missing here?

A small test app is set up like this:

init.js:

//@codekit-prepend "vendor/jquery-1.7.2.js"
//@codekit-prepend "vendor/underscore.js"
//@codekit-prepend "vendor/backbone.js"

// Setup namespace for the app
window.app = window.app || {};

//@codekit-append "models/Ride.js"

Ride.js:

(function() {
    window.app.Ride = Backbone.Model.extend({

        initialize: function() {
            console.log("Ride initialized");
        }
    });
})();

CodeKit's JSHint check reports that both Backbone and console are not defined. What am I missing here?

Share Improve this question asked Jul 31, 2012 at 22:42 ipavlicipavlic 4,96610 gold badges41 silver badges79 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 18

JSHint doesn't run your code so it doesn't know about any modules you included in other files. You have to specifically tell it about all global variables you plan to use in Ride.js. In your case it will be: /*global Backbone */. console is disallowed by default because it is not a very good idea to ship your software with filled console.log calls. To remove this warning you can use /*jshint devel:true */.

So in the end your file should look like this to pass JSHint check:

/*jshint devel:true */
/*global Backbone */

(function() {
    window.app.Ride = Backbone.Model.extend({

        initialize: function() {
            console.log("Ride initialized");
        }
    });
})();

More info here: http://www.jshint./options/

Bryan here. CodeKit does check your files in a full, global context. (That is, it bines them first, so variables declared in an earlier file will be valid in a later one. This assumes you use CodeKit to bine the files, either with @codekit-prepend/append statements or drag/drop import links set up in CodeKit itself). If you're bining your JS files some other way (such as a build script) then CodeKit is unaware that the files go together and therefore it checks each one separately.

You can use the ment flags in the answer above, or you can configure JSHint's options directly in CodeKit. See the preferences window (or project settings area, if your project uses project-level settings). You can also enter custom globals there as well, which will remove those warnings.

Cheers!

发布评论

评论列表(0)

  1. 暂无评论