简体   繁体   English

Require.js的难度加载模块

[英]Difficulty Loading Modules with Require.js

I'm trying to load and use a module I defined with Require. 我正在尝试加载和使用通过Require定义的模块。 As far as I can tell, I'm following the patterns on the official site, but I'm not getting the loaded module inside the require call. 据我所知,我遵循的是官方网站上的模式,但没有在require调用中获取已加载的模块。

main.js: main.js:

define(function (require) {
    require(['./util'], function(util){
       util.dictionary(); 
    });
    ...
});

util.js: util.js:

define(function(){
    "use strict";

    var util = {};
    ...
    return util;
});

With this, util.dictionary() fails because util is undefined. 这样,由于未定义util,因此util.dictionary()失败。

Both files are on the same directory level, and I haven't defined any baseURL for Require. 这两个文件都在同一目录级别,并且我还没有为Require定义任何baseURL。

Why is this failing? 为什么会失败?

After a lot of poking around, I discovered that Chrome was using a cached versions of some of my files, and clearing the cache caused the modules to load correctly. 经过一番摸索,我发现Chrome浏览器正在使用某些文件的缓存版本,清除缓存会导致模块正确加载。

Yes, I'm a web development noob. 是的,我是网络开发新手。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM