[英]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.