这段代码 怎么访问到里面的函数?

每天进步一点点e 2013-07-24 03:46:42

$.extend({
weibo:function(){
// var mm = new aa(opt.type);
$.extend(this,{
ff:function(){
alert('777');
},
plugin:{}
}); /// ********

/* function aa(){
this.create = function(){
alert('11111');
}
}*/
}
});

求教一下怎么访问到ff 函数?
...全文
114 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
l676331991 2013-07-25
  • 打赏
  • 举报
回复
引用
2.js是这样的
jQuery.extend(weibo().plugin, {
	image:function(element, options){    
	}
});
jQuery.extend(weibo().plugin.image, {
        ee:function(){
		   alert('ccccc');
		}
})
我怎么访问到ee这个函数呢
weibo().plugin.image? extend就是把第二个参数里的属性扩展到第一个上了,直接用第一个对象的引用.ee()就行了,但是你这里的weibo().plugin.image,每次都调用weibo()么?
  • 打赏
  • 举报
回复
我是jquery小白,首先谢谢大家的热心帮忙
  • 打赏
  • 举报
回复
引用 7 楼 l676331991 的回复:
[quote=引用 5 楼 yang131261 的回复:] [quote=引用 1 楼 l676331991 的回复:]

$.weibo();
//接下来ff就挂到jQuery下了已经
$.ff(); //alert("77")
求教一下这个 plugin:{} 是什么意思?[/quote] plugin是插件的意思,放到这个plugin:{a:1}里的,就可以用$.plugin.a来访问了。 其实这里关键是要理解$.extend,$.extend故名思议就是扩展,带两个以上参数时,将所有参数的属性合并到第一个参数上,如果出现重复,右边覆盖左边的,同时返回合并后的对象。

$.extend({a:1,b:2},{a:2,c:1}); // => {a: 2, b: 2, c:1}
带一个参数时,$.extend({a:1}) <=> $.extend($,{a:1}); 等价于扩展jQuery本身。[/quote] 不好意思啊 在求教一下大神 1.js是这样的
$.extend({
    weibo:function(){
       var mm = new aa();
       $.extend(this,{
                ff:function(){
                    mm.create();      
                },
                plugin:{}
        }); 
        function aa(){
            this.create = function(){
                alert('99999');
            }
        }
    }
});
2.js是这样的
jQuery.extend(weibo().plugin, {
	image:function(element, options){    
	}
});
jQuery.extend(weibo().plugin.image, {
        ee:function(){
		   alert('ccccc');
		}
})
我怎么访问到ee这个函数呢
tony4geek 2013-07-24
  • 打赏
  • 举报
回复
  plugin:{
a:"a"
}
 $.weibo();
//注册属性,事件
alert($.plugin.a);
l676331991 2013-07-24
  • 打赏
  • 举报
回复
引用 5 楼 yang131261 的回复:
[quote=引用 1 楼 l676331991 的回复:]

$.weibo();
//接下来ff就挂到jQuery下了已经
$.ff(); //alert("77")
求教一下这个 plugin:{} 是什么意思?[/quote] plugin是插件的意思,放到这个plugin:{a:1}里的,就可以用$.plugin.a来访问了。 其实这里关键是要理解$.extend,$.extend故名思议就是扩展,带两个以上参数时,将所有参数的属性合并到第一个参数上,如果出现重复,右边覆盖左边的,同时返回合并后的对象。

$.extend({a:1,b:2},{a:2,c:1}); // => {a: 2, b: 2, c:1}
带一个参数时,$.extend({a:1}) <=> $.extend($,{a:1}); 等价于扩展jQuery本身。
  • 打赏
  • 举报
回复
4L也正确,谢谢4L的热心回答
  • 打赏
  • 举报
回复
引用 1 楼 l676331991 的回复:

$.weibo();
//接下来ff就挂到jQuery下了已经
$.ff(); //alert("77")
求教一下这个 plugin:{} 是什么意思?
lzh_me 2013-07-24
  • 打赏
  • 举报
回复

new $.weibo().ff();
tony4geek 2013-07-24
  • 打赏
  • 举报
回复
楼上不错。哈哈/
  • 打赏
  • 举报
回复
引用 1 楼 l676331991 的回复:

$.weibo();
//接下来ff就挂到jQuery下了已经
$.ff(); //alert("77")
谢谢你的热心回答 马上结贴
l676331991 2013-07-24
  • 打赏
  • 举报
回复

$.weibo();
//接下来ff就挂到jQuery下了已经
$.ff(); //alert("77")

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧