简体   繁体   English

未捕获的TypeError:使用require.js时undefined不是函数

[英]Uncaught TypeError: undefined is not a function when using require.js

I'm new to require.js so I may not be using it correctly, but as far as I know, I can't find what's causing the error. 我是require.js的新手,所以我可能无法正确使用它,但是据我所知,我找不到导致错误的原因。

Structure 结构体

index.html
Scripts\
  - jquery-2.1.1.min.js
  - require.js
  \app
    - main.js
  \lib
    - work-requests.js
    - controller-base.js
    - util.js

index.html 的index.html

<script src="Scripts/require.js" data-main="Scripts/app/main"></script>

main.js main.js

requirejs.config({
    baseUrl: 'Scripts/lib',
    paths: {
        jquery: '../jquery-2.1.1.min',
    },
});
requirejs(['jquery', 'util', 'work-requests'], function ($, util, work_requests) {
    $(function () {
    var foo = new work_requests.get_all(); // <-- error "Uncaught TypeError: undefined is not a function
});

work-requests.js 工作requests.js

define(['controller-base'], function (controller_base) {
    return function () {
        var that = controller_base('work-requests')

        return that;
    }
});

controller-base.js 控制器base.js

define(['jquery'], function ($) {
    return function (controller_name) {
        var that = {};
        that.controller = controller_name;

        that.get_all = function () {
            return $.ajax({
                type: 'get',
                contentType: 'application/json',
                url: _api_root + '/' + that.controller,
            });
        };
        return that;
    };
});

util.js util.js中

define({
  foo: function(data){},
});

Your require.js setup is completely fine. 您的require.js设置完全正确。 Did you try changing 你尝试改变吗

var foo = new work_requests.get_all();

to

var foo = new work_requests();
var bar = foo.get_all();

?

Duplicate. 重复。

You're looking for mainConfigFile: 'path/to/main.js' requireJS optimization: undefined is not a function 您正在寻找mainConfigFile: 'path/to/main.js' main.js'requireJS优化:undefined不是一个函数

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

相关问题 Require.js Uncaught TypeError:undefined不是函数 - Require.js Uncaught TypeError: undefined is not a function Require.js未被捕获的TypeError:jqOAuth不是一个函数 - Require.js Uncaught TypeError: jqOAuth is not a function Require.js:未捕获的TypeError:对象函数…没有方法 - Require.js : Uncaught TypeError: Object function … has no method require.js未捕获的TypeError:对象的属性&#39;$&#39; <Object> 不是一个功能 - require.js Uncaught TypeError: Property '$' of object #<Object> is not a function require.js uncaught typeerror:无法读取属性&#39;__module_path__; 未定义的 - require.js uncaught typeerror: cannot read property '__module_path__; of undefined require.js和bone.js获取未捕获的TypeError - require.js and backbone.js getting Uncaught TypeError Require.js / Jquery Datable:未定义不是函数 - Require.js/Jquery Datable : undefined is not a function 使用Require.js未定义车把 - Handlebars is undefined using Require.js Require.js + TypeError:优化后未定义Backbone - Require.js + TypeError: Backbone is undefined after optimization Backbone.js和Require.js-未捕获的TypeError:对象函数(){return parent.apply(this,arguments); }没有方法“开” - Backbone.js and Require.js - Uncaught TypeError: Object function (){ return parent.apply(this, arguments); } has no method 'on'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM