我正在尝试编写一个插件来扩展 jQuery 中的现有功能,例如
(function($)
{
$.fn.css = function()
{
// stuff I will be extending
// that doesn't affect/change
// the way .css() works
};
})(jQuery);
我只需要扩展一些位.css()
功能。请介意我问,我正在考虑 PHP 课程,因为你可以className extend existingClass
,所以我问是否可以扩展 jQuery 函数。
当然...只需保存对现有函数的引用,然后调用它:
(function($)
{
// maintain a reference to the existing function
var oldcss = $.fn.css;
// ...before overwriting the jQuery extension point
$.fn.css = function()
{
// original behavior - use function.apply to preserve context
var ret = oldcss.apply(this, arguments);
// stuff I will be extending
// that doesn't affect/change
// the way .css() works
// preserve return value (probably the jQuery object...)
return ret;
};
})(jQuery);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)