jquery小部件,_create或_init [英] jquery widget, _create or _init

查看:109
本文介绍了jquery小部件,_create或_init的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些jquery插件扩展小部件使用_create方法,而其他人使用_init方法,有人可以解释两者之间的差异吗?

Some jquery plugin extend widget use _create method, while others use _init method, can someone explain the differences between the two?

还有什么指导什么时候更好扩展小部件或直接扩展jquery.fn?

Also any guidance on when it is better to extend widget or directly extend jquery.fn?

推荐答案

扩展小部件(而不是$ .fn)的缺点是你在jquery-ui上创建了一个依赖项,它定义了一个小部件class。对于不使用jquery-ui的插件用户而言,这种依赖可能会很昂贵。

The downside to extending widget (as opposed to $.fn) is that you create a dependency on jquery-ui which defines the widget "class". That dependency could be expensive for users of your plugin that don't also use jquery-ui.

就_create vs _init而言,我很确定_init首先出现,然后在最近的修订中,他们介绍并支持_create。我可能错了,但我相信_init仍然受到支持。如果是,则两者之间不应有任何差异。

As far as _create vs _init goes, I'm pretty sure that _init came first and then in a recent revision they introduced and favor _create. I might be wrong about this, but I believe that _init is still supported. If it is then there shouldn't be any differences between the two.

这篇关于jquery小部件,_create或_init的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆