[英]How Ember does Ember.version() from browser console?
I was studying Javascript / Ember and I was looking into its source codes. 我正在研究Javascript / Ember,并且正在研究其源代码。 https://github.com/emberjs/ember.js/
https://github.com/emberjs/ember.js/
While I was studying, I found something interesting and I wonder how it works. 在学习期间,我发现了一些有趣的东西,并且想知道它是如何工作的。 As you may know, you can get version number of Ember if you type Ember.VERSION in the browser console.
您可能知道,如果在浏览器控制台中键入Ember.VERSION,则可以获得Ember的版本号。 I wanted to do in my project so I started searching codes how Ember did it.
我想在我的项目中这样做,所以我开始搜索Ember的代码。
I could find 我可以找到
// in packages/ember/lib/index.js
Ember.VERSION = VERSION;
...
// Later exports Ember object
However I can't find how Ember makes it available in window (from browser). 但是我找不到Ember如何使其在窗口中(从浏览器)可用。 I expected they did like... window['Ember'] = Ember or something like that but I couldn't find any similar codes.
我希望他们确实喜欢... window ['Ember'] = Ember或类似的东西,但是我找不到任何类似的代码。
I wonder if there is anyone knows how they make Ember object available throughout window. 我想知道是否有人知道如何使Ember对象在整个窗口中可用。 Thank you so much!
非常感谢!
ember-cli-app-version addon can expose your application's name and version info. ember-cli-app-version插件可以公开您应用程序的名称和版本信息。 So you can put your version in your templates via an helper .
因此,您可以通过帮助程序将版本放入模板中。
The addon also registers the infos to the Ember.libraries
so that ember-inspector can understand. 该插件还将信息注册到
Ember.libraries
以便ember-inspector可以理解。 You can access the Ember.libraries
in a such way: 您可以通过以下方式访问
Ember.libraries
:
Ember.libraries._registry.filter(item=>{return item.name==='my-app-name';})[0].version
The addon can give you both package.json
information or git describe
result. 该插件可以为您提供
package.json
信息或git describe
结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.