I'm refactoring an in house framework from using nested namespaces towards using amd (require.js).
In the 'old' version I have 2 files.
Core.js
Core.Window.js
Both of them contain utitily functions, but only Core.js can be used in WebWorkers. Window.js accesses the DOM.
Let's say I Core.js looks like this;
define([], function () {
function specialfunction() {
return "I'm special";
}
return {
specialfunction: specialfunction
}
});
And then in Core.Window I create a dependency. But I extend the core object;
define(["core"], function (core) {
core.doSomethingDommy = function (id) {
return document.getElementById(id);
}
return core;
});
So now in the normal window scope I can define "core.window" and in the worker scope I can define "core". I end up with a familair object to other implementors in both case, e.g. core.
Is this in anyway considered bad practice?