我正在将Ember开发为一个插件&在我的tests\dumm\app.js中,我有
App = Ember.Application.extend({
modulePrefix: config.modulePrefix,
});
我的问题与通过Ember应用程序访问全局变量有关。
我必须做吗
window.App = App;
仅在上面的位置(即,我将使用Ember.Application.extend()的位置)
或者我也可以在其他地方做吗?
您可以在js文件中定义一个类,例如:
import Ember from 'ember';
const MyClazz = Ember.Object.extend({
// your properties and methods
});
const myObj = MyClazz.create({});
export default myObj;
这个对象将作为一个全局对象,你可以从任何你想要的地方访问这个对象,比如:
import MyObj from '/...path';
...
MyObj.get('...');