2013-04-08 107 views
14

我有一個標準的Embermain.js文件,它開始像這樣:jshint抱怨:「灰燼」沒有定義

this.App = Ember.Application.create({ 
    LOG_TRANSITIONS: true, 
    VERSION: '1.0.0', 
    ready: function() { 
     console.log('App version: ' + App.VERSION + ' is ready.'); 
    } 
}); 

通過jshint運行此抱怨灰燼沒有被定義,這是這個特殊的文件真實在服務器中,在部署階段。因此,顯示了很多錯誤消息。

Ember在瀏覽器中index.html提供由script標籤:

<script src="scripts/vendor/ember-1.0.0-rc.2.js"></script> 

我怎麼能告訴jshintEmber

回答

16

下應該這樣做:

/*global Ember */ 
this.App = Ember.Application.create({ 
    LOG_TRANSITIONS: true, 
    VERSION: '1.0.0', 
    ready: function() { 
     console.log('App version: ' + App.VERSION + ' is ready.'); 
    } 
}); 

發現在JS Hint Docs

+0

你的意思是在實例化this.App之前,在'main.js'中添加'/ * global Ember * /'?這不適合我。 – dangonfast 2013-04-09 02:46:05

+0

然後,你的JSHint設置一定有問題。它適用於我,正如你所看到的,我從Docs中獲得了它。 – mavilein 2013-04-09 08:36:42

+0

我在jshint郵件列表中找到了答案:您不能在'global'之前放置空格。它必須是這樣的:'/ * global Ember * /'。你能改正你的答案,以便我能接受嗎? – dangonfast 2013-04-09 09:13:28

16

如果您正在使用新的ES6,例如從ember-cli,必須導入恩貝爾:

import Ember from 'ember'; 

我跟在Evil Trout's Ember Reddit tutorial之後,發現下面的錯誤Ë測試:

my-new-app/routes/subreddit.js should pass jshint. 
my-new-app/routes/subreddit.js: line 3, col 16, 'Ember' is not defined. 

添加上述線的my-new-app/routes/subreddit.js頂部通過測試。