0

I was studying Javascript / Ember and I was looking into its source codes. 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. I wanted to do in my project so I started searching codes how Ember did it.

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). I expected they did like... window['Ember'] = Ember or something like that but I couldn't find any similar codes.

I wonder if there is anyone knows how they make Ember object available throughout window. Thank you so much!

ryan
  • 503
  • 2
  • 7
  • 17
  • Possible duplicate of [What's the difference between a global var and a window.variable in javascript?](https://stackoverflow.com/questions/6349232/whats-the-difference-between-a-global-var-and-a-window-variable-in-javascript) – Siguza Jul 06 '17 at 13:26
  • @Siguza Thank you for the comment :) But I am not sure why this is a possible duplicate... I know what is window and its variable. I just want to know how Ember "assigns" variable to window, since I couldn't find any relevant codes from their source codes. – ryan Jul 06 '17 at 13:47
  • Have you _read_ that question and its answer(s)? – Siguza Jul 06 '17 at 13:58

1 Answers1

0

ember-cli-app-version addon can expose your application's name and version info. 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. You can access the Ember.libraries in a such way:

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.

ykaragol
  • 6,139
  • 3
  • 29
  • 56