简体   繁体   English

Require.js未被捕获的TypeError:jqOAuth不是一个函数

[英]Require.js Uncaught TypeError: jqOAuth is not a function

I would like to use jQuery OAuth library in my application. 我想在我的应用程序中使用jQuery OAuth库。

Right now I'm trying to initialize it in main.js file. 现在,我正在尝试在main.js文件中main.js进行初始化。

I defined paths for this lib and it's dependency store.js : 我为这个库及其依赖项store.js定义了路径:

requirejs.config({
   paths: {
    store: "../Scripts/store.min",
    jqueryOAuth: "../Scripts/jquery.oauth"
   }
});

And I took an example from jQuery OAuth page how to do an initialization: 我以jQuery OAuth页面中的示例为例进行了初始化:

define(["store", "jqueryOAuth"], function (store, jqOAuth) {
    if (!store.enabled) {
        alert("Store not enabled");
        return;
    }

    var auth = new jqOAuth({ // <--- Uncaught TypeError: jqOAuth is not a function
        events: {
            login: function() {},
            logout: function() {},
            tokenExpiration: function() {}
        }
    });
});

When I open my website I get the error in console: 当我打开网站时,控制台出现错误:

Uncaught TypeError: jqOAuth is not a function

But if you take a look at jquery.oauth.js file, you'll see, that there's a function called jqOAuth. 但是,如果您看一下jquery.oauth.js文件,就会发现有一个名为jqOAuth的函数。

Do you have any idea what I'm doing wrong? 你知道我在做什么错吗? I'm quite new to javascript stuff and maybe I'm missing something? 我对javascript东西很陌生,也许我缺少一些东西?

Turns out, that I was overriding global jqOAuth function with my local variable of the same name. 原来,我正在用同名的本地变量覆盖全局jqOAuth函数。

Here's working code: 这是工作代码:

define(["store", "jqueryOAuth"], function (store) {
    if (!store.enabled) {
        alert("Store not enabled");
        return;
    }

    var auth = new jqOAuth({
        events: {
            login: function() {},
            logout: function() {},
            tokenExpiration: function() {}
        }
    });
});

声明:本站的技术帖子网页,遵循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:对象函数…没有方法 - 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 未捕获的TypeError:使用require.js时undefined不是函数 - Uncaught TypeError: undefined is not a function when using require.js require.js和bone.js获取未捕获的TypeError - require.js and backbone.js getting Uncaught TypeError 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' 未捕获的错误:require.js中没有定义调用 - Uncaught Error: No define call in require.js require.js uncaught typeerror:无法读取属性&#39;__module_path__; 未定义的 - require.js uncaught typeerror: cannot read property '__module_path__; of undefined require.js模块中的递归函数 - Recursive function inside a require.js module 未捕获的AssertionError:路径必须是Require.js中的字符串错误 - Uncaught AssertionError: path must be a string error in Require.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM