I've written a small webapp in JavaScript, and am now essentially rewriting it to use RequireJS. I'm doing this partly to get more familiar with RequireJS (which I have little experience with), as well as for ease of maintaining and upgrading the app.
I'm hoping to get feedback on whether the structure I'm looking at implementing is reasonable/useful/extensible/totally insane. I've been through the require docs, reading related SO posts and some samples on GitHub, but I'm not sure I'm totally 'getting' Require.
If there are fundamental flaws in the logic it'd be great to get some links to resources (either JS or RequireJS specific), and to get feedback about the overall structure of the app itself. Suggestions for design patterns also very much appreciated, there's some stuff in there that feels kind of counter intuitive.
main.js
require({
paths: {
jquery: '../bower_components/jquery/jquery'
}
}, function() {
'use strict';
require(['jquery', 'app', 'reader', 'env'], function($, App, Reader, Env) {
$(document).ready(function() {
var app = new App(
new Reader(),
new Env()
);
});
})
});
app.js
define(function() {
return function(reader, env) {
this.reader = reader,
this.env = env
};
});
reader.js (it's an online e-reader)
define(['jquery'], function($) {
return function() {
this.components = [],
this.firstPage = null,
this.lastPage = null,
this.maxFontSize = function() {
return this.env.isIOS() ? 120 : 160;
}
};
});
env.js
define(['jquery'], function($) {
return function() {
this.isIOS = function() {
return navigator.userAgent.match(/(iPad|iPhone|iPod)/i) ? true : false; // for example.
}
};
});