尝试定义几个函数,如下所示:
user = (function() {
var friends_list = (function() {
$.get('/ajax/user/friends_list', function(data) {
......
所以我可以稍后在需要时调用他们,就像 user.friends_list()
但现在,我得到的唯一结果是以下错误:
TypeError: Object function () {
var friends_list = (function() {
$.get(....
我只是不知道还能去哪里看,有什么建议吗?
最佳答案
您需要将 user 创建为对象,在您的情况下,friends_list
是一个闭包方法,它将在函数外部可用
user = {
friends_list : function(){
....
}
}
关于javascript - 定义 jQuery 函数时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16166041/