jQuery jQuery.sub()Method

jQuery 杂项方法jQuery Miscellaneous Methods

Examples

Add a method to jQuery sub so that it is not exposed outside

(function(){ var sub = jQuery.sub(); sub.fn.myCustomMethod = function(){ return 'just for me'; }; sub(document).ready(function() { alert(sub('body').myCustomMethod()); }); alert(typeof jQuery('body').myCustomMethod); //underfine })();

Try it Yourself »

Definition and Usage

$.sub() function creates a new copy of jQuery, whose properties and methods can be modified without affecting the original jQuery object.


Note:1. It has been deprecated since jQuery 1.7,In jQuery 1.8, it will be moved into a plugin.
2. $.sub() does not attempt to perform any kind of isolation. All methods in the jQuery copy still point to the original jQuery. (For example, event binding and triggering will still be done through the original jQuery, and data will also be bound to elements through the original jQuery. Ajax requests and events are also run through the original jQuery, etc.)


Syntax

Tip:This method does not accept any parameters.
$.sub()


实例

More Examples

Override some jQuery methods
Override some jQuery methods to provide new functionality.

Create a plugin
Create a plugin that returns the plugin's specific methods.


jQuery 杂项方法jQuery Miscellaneous Methods

Other Extensions