javascript - Class and Object confusion within Ember.js -
this basic question i'm little bit confounded. understanding convention dictates class definitions capitalised object instances not. when following:
app = require("app"); module.exports = app.authmanager = ember.object.extend({ apikey: null, // load current user if cookies exist , valid init: function() { this._super(); var accesstoken = $.cookie('access_token'); var authuserid = $.cookie('auth_user'); if (!ember.isempty(accesstoken) && !ember.isempty(authuserid)) { this.authenticate(accesstoken, authuserid); } }, // ... }
i assume defining authmanager's class definition. if this:
module.exports = app.applicationroute = ember.route.extend({ init: function() { this._super(); app.authmanager = app.authmanager.create(); } });
my understanding app.authmanager = app.authmanager.create();
instantiates instance , applicationrouter pretty first thing executed in ember app. right? if so, shouldn't convention dictate instance called authmanager
? also, typical put class definition same namespace object? suspect may come down relatively shallow understanding of js appreciated.
if so, shouldn't convention dictate instance called authmanager?
yes indeed, line:
app.authmanager = app.authmanager.create();
should read, avoid confusion (although it's singleton , singletons capitalized)
app.authmanager = app.authmanager.create();
since creating instance of app.authmanager
class definition, @ least how ember dictates it.
also, typical put class definition same namespace object
i guess not, (however javascript let's sort of things) therefore lowercase naming of object instance, rather capitalized class definition. later on create more instances of same class like:
app.foo = app.authmanager.create(); app.bar = app.authmanager.create();
(obviously doesn't make sense class meant singleton, point)
hope helps
Comments
Post a Comment