I'm having an issue with RequireJS where my main.js script has a reference to a dependency, which is loaded but not resolved when the callback in main.js requesting this dependency is run.
My directory structure is:
index.htm
scripts/
require.js
main.js
feeds/
feed.js
index.htm:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Blah</title>
<script data-main="scripts/main" src="scripts/require.js"></script>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
main.js:
require(["feeds/feed"], function(feed) {
console.log("A");
require.ready(function() {
console.log("B");
console.log(feed.val);
});
});
feed.js:
console.log("C");
require(function() {
console.log("D");
return {
val: "E"
}
})
And the console output, suggesting that the dependency files are being loaded, but not resolved correctly:
C
A
B
Uncaught TypeError: Cannot read property 'val' of null
I must be missing something really obvious here, but whatever documentation I read up on, the problem doesn't seem to be revealing itself. Any ideas?
I'm having an issue with RequireJS where my main.js script has a reference to a dependency, which is loaded but not resolved when the callback in main.js requesting this dependency is run.
My directory structure is:
index.htm
scripts/
require.js
main.js
feeds/
feed.js
index.htm:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Blah</title>
<script data-main="scripts/main" src="scripts/require.js"></script>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
main.js:
require(["feeds/feed"], function(feed) {
console.log("A");
require.ready(function() {
console.log("B");
console.log(feed.val);
});
});
feed.js:
console.log("C");
require(function() {
console.log("D");
return {
val: "E"
}
})
And the console output, suggesting that the dependency files are being loaded, but not resolved correctly:
C
A
B
Uncaught TypeError: Cannot read property 'val' of null
I must be missing something really obvious here, but whatever documentation I read up on, the problem doesn't seem to be revealing itself. Any ideas?
Share Improve this question asked Apr 8, 2011 at 4:56 StoiveStoive 11.3k4 gold badges26 silver badges32 bronze badges1 Answer
Reset to default 12You're using require
to define your modules, where you should be using define
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744126640a4559644.html
评论列表(0条)