Requirejs、jshint 和命名约定

Requirejs, jshint and naming conventions

本文关键字:命名约定 jshint Requirejs      更新时间:2023-09-26

你能在requirejs路径的命名约定中使用点和连字符吗?

  paths: {
    chosen: '../../bower_components/chosen/chosen.jquery',
    dateBuilderPlugin: 'vendor/dateBuilder-plugin',
    jquery: '../../bower_components/jquery/dist/jquery',
    jquery.ui.widget: '../../bower_components/blueimp-file-upload/js/vendor/jquery.ui.widget',
    jquery.iframe-transport: '../../bower_components/blueimp-file-upload/js/jquery.iframe-transport',
    jqueryFileupload: '../../bower_components/blueimp-file-upload/js/jquery.fileupload',
    jqueryFileuploadProcess: '../../bower_components/blueimp-file-upload/js/jquery.fileupload-process',
    jqueryFileuploadImage: '../../bower_components/blueimp-file-upload/js/jquery.fileupload-image',
    jqueryFileuploadValidate: '../../bower_components/blueimp-file-upload/js/jquery.fileupload-validate',
},

当我使用此命名约定 ( jquery.iframe-transport ) 时,我在 jshhint 中收到重复键错误。它说jquery已经定义,因为它忽略了-.后面的名称。

我正在使用RequireJS和jshint和bower。命名约定是在插件中设置的,除非我保存文件并手动引用它们,否则我会 uisng,这破坏了使用 bower 等的对象。

我想您是在问paths对象中的是否可以包含破折号和句点。是的,他们可以。但是,您必须使用引号。所以"jquery.ui.widget": ...用引号,而不是jquery.ui.widget: ...没有引号。jquery.iframe-transport也是如此:您必须使用引号。所以"jquery.iframe-transport": ....

这是一个 JavaScript 语法约束,而不是 RequireJS 强加的约束。