I am trying to use requireJS, but I want to build a hierarchy of dependencies: main
requires obr.platcom
and obr.platcom
requires obr
(for example).
I have this file hierarchy:
- index.html -> js - main.js -> lib - jquery.js - require.js -> obr [my own 'libraries'] - obr.js - obr.platcom.js
index.html
<!DOCTYPE html> <html lang="es"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="viewport" content="initial-scale=1.0, width=device-width" /> <title>Platcom</title> <script type="text/javascript" src="js/lib/jquery.js"></script> <script data-main="js/main" src="js/lib/require.js"></script> </head> <body> </body> </html>
main.js
$(document).ready(function() { require(["obr/obr.platcom"], function() { obr.hola(); var myPlatcom = obr.platcom(); myPlatcom.test(); }); });
obr.js
var obr = {}; obr.hola = function() { alert('Hola OBR'); };
obr.platcom.js
require(["obr.js"],function() { obr.platcom = function(params) { var that = {}; var test = function test() { alert('Hola Platcom!'); } that.test = test; return that; } });
If I need the obr
and obr.platcom
in main
, everything works, but if I use this nested style, I get the following error:
Uncaught ReferenceError: obr is not defined main.js:3
Do you know what I am doing wrong? Thank you in advance.
source share